Qt platform plugin "windows"
Cannot instantiate a QApplication.
import sys
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
Results in:
This application failed to start because it could not find or load the Qt platfo
rm plugin "windows".
Available platform plugins are: minimal (from C:\Python27\lib\site-packages\PyQt
5\plugins\platforms), offscreen (from C:\Python27\lib\site-packages\PyQt5\plugin
s\platforms), windows (from C:\Python27\lib\site-packages\PyQt5\plugins\platform
s).
Reinstalling the application may fix this problem.
Having encountered the problem in the past, I could solve it by appending the plugins by hand like this:
import os
import sys
import PyQt5
dirname = os.path.dirname(PyQt5.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
However this produces the same error. The odd thing is that it says it can't load the plugin, and then lists the plugin as one of the available ones. Maybe a permission issue? Yet permissions on the files are unlocked and even replacing it with the source original from the Qt installation yields the same results. Removing the plugin from the directory correctly removes it from plugins found.
depends.exe
Running depends on qwindows.dll yields a few interesting results.
However each of these are available directly within the PyQt5 Python package directory.
It works
If keeping the original installation of Qt on the PATH, PyQt5 seems to work. From a terminal:
# Keeping C:\Qt\Qt5.3.0\5.3\msvc2013_64\bin on the PATH
import os
import sys
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
button = QtWidgets.QPushButton("Hello World")
button.show()
So there must be something within this directory which is requited by PyQt5. But copying the entire contents into the PyQt5 Python library directory yields no better results.
I've had the same issue with cx_Freeze - there for me it helped to copy libEGL.dll to the frozen package.
Maybe that helps in some way?
Thanks @The-Compiler, I'll have a look at that tonight. You're thinking of just putting it in the root PyQt5 Python library directory?
I'm afraid I have no idea what to do with it (and I don't know anything about putting C projects on PyPI at all), but that's where I remember the message from (with windows being listed in the available platforms as well).
I'm afraid I have no idea what to do with it
No problem, it does help to narrow down the dependencies and this seems to be one of them.
(and I don't know anything about putting C projects on PyPI at all
Though I'm sure there are practices for doing this more gracefully, the way I'll handle it initially is the same as with any Python package with package data; to simply include all non-Python files in the package_data argument of setup().
- https://github.com/pyqt/pyqt5/blob/master/setup.py
Seems to work now.
Here are the changes:
- Compiled using Qt 5.3.1 rather than 5.3.2 as it isn't yet supported
- Binaries was coming from the Python 3 binaries supplied via Riverbank's website but are now coming directly from the Qt distribution.
-
__init__.pynow initialisesPATHandQT_QPA_PLATFORM_PLUGIN_PATH
Platform plug-ins
The Riverbank distribution ships with a qt.conf which initialises the PATH and platform plugin path, this release instead initialises these via the __init__.py so as to not need to provide the qt.conf file.
Pre-requisities
To run this VS2013 compiled release of PyQt5, you'll need the VS2013 redistributables.
This problem re-surfaces in certain situations that I am unable to re-produce.

The above was reported by @davidmartinezanim on a Windows 7 machine, running Python 2.7.9 x64 with Visual C++ 2013 re-distributable installed.
I am having the same error with Python 2.7.9 x64 on Windows 8. I just freshly installed. Looking through the qt forums this is a problem for qt apps too. I have read that the app needs to have qt.conf and the platforms folder in its path. I'll check this later today or tomorrow.
Well, I have a similar but slightly different problem. The windows platform option (or any option for that matter) doesn't show up at all. Interestingly, your above method of adding the os.environ value worked. The weird part is that setx QT_QPA_PLATFORM_PLUGIN_PATH "C:\Python27\lib\site-packages\PyQt 5\plugins\platforms" didn't work at all. I couldn't call the variable from cmd like PATH, and it didn't work with a Python script. Very weird.
If you are installing from GitHub, and not PyPI, then you should have 5.4. If you do, have a go with this to see if it changes anything.
https://github.com/pyqt/python-qt5/wiki/Installation#install
It will create a qt.conf for you with the appropriate settings for your system.
To check the version of PyQt, try this.
>>> import PyQt5
>>> PyQt5.pyqt_version
'5.3.2'
I installed from Github. I actually followed the steps you are pointing to, and I still got the error. Interesting. I just ran it again from the downloaded directory, and that might have fixed it. So maybe an extra step of running it again? Or just running it after install?
Well, I just re-installed from Github, and it worked if I ran the qt.conf generator after running python setup.py install. Very strange.
It got weirder. I just got the message again. I tried generating a qt.conf again, but that didn't work. This is very annoying.
EDIT: and it is back. Perhaps re-running python -c "import util;util.createqtconf()"did work. I think I just needed to restart my ide. I am starting to think this is a valid solution.
The behaviour is that Qt looks for qt.conf in the same directory as the current executable. Have a look at what executable your IDE is actually launching, it might be different from c:\Python27\python.exe. I've heard of this happening with PyCharm, for example, when running in debug versus release mode.
You can print the current executable like this.
import sys
print sys.executable
There should be a qt.conf in the same directory, and it should contain lines pointing to where your PyQt5 installation is at.
- http://doc.qt.io/qt-5/qt-conf.html
It can get really complicated, so I don't blame you for getting frustrated. I've been there. :(
See the Bundling section of the wiki here for the full story.
- https://github.com/pyqt/python-qt5/wiki/Updating-the-repository
Okay, I am using PyCharm, but I am using Python27's python.exe (checked using your code). I think I have the problem. I was running python -c "import util;util.createqtconf()" from the downloaded directory, so all of the path information was pointing to Downloads\python-qt5, instead of the one in site-packages. I am not sure about the qt.conf. It currently is pointing to Lib\site-packages\PyQt5.
So having the install directory solved this issue, but raised another, it is trying to find my QtQml dll in my downloads (which doesn't exist).
EDIT: And none of the potential answers have done anything. I think I might need to poke around in my PATH and make sure things are pointing to the right places.
EDIT2: Still nothing. I have my PATH pointing towards the right folders, but I still have the problem.
Just to clarify, this package does not require me to install Qt 5 as a dependency for this? It looks like python-qt5 includes all the necessary DLLs? Am I getting that right? Thanks!
That's right!
So I got this to work before, and now it's not working again :(
PyInstaller Bootloader 3.x LOADER: executable is Q:\exec\win\dist\main\main.exe LOADER: homepath is Q:\exec\win\dist\main LOADER: _MEIPASS2 is NULL LOADER: archivename is Q:\exec\win\dist\main\main.exe LOADER: No need to extract files to run; setting extractionpath to homepath LOADER: SetDllDirectory(Q:\exec\win\dist\main) LOADER: Already in the child - running user's code. LOADER: Python library: Q:\exec\win\dist\main\python27.dll LOADER: Loaded functions from Python library. LOADER: Manipulating environment (sys.path, sys.prefix) LOADER: sys.prefix is Q:\exec\win\dist\main LOADER: Setting runtime options LOADER: Initializing python LOADER: Overriding Python's sys.path LOADER: Post-init sys.path is Q:\exec\win\dist\main LOADER: Setting sys.argv LOADER: setting sys._MEIPASS LOADER: importing modules from CArchive LOADER: extracted struct LOADER: callfunction returned... LOADER: extracted pyimod01_os_path LOADER: callfunction returned... LOADER: extracted pyimod02_archive LOADER: callfunction returned... LOADER: extracted pyimod03_importers LOADER: callfunction returned... LOADER: Installing PYZ archive with Python modules. LOADER: PYZ archive: out00-PYZ.pyz LOADER: Running pyiboot01_bootstrap.py LOADER: Running pyi_rth_qt5.py Qt: Untested Windows version 10.0 detected! LOADER: Running pyi_rth_qt5plugins.py LOADER: Running pyi_rth_win32comgenpy.py LOADER: Running main.py RUNNING SMARTSHARE: Q:\exec\win\dist\main\PyQt5\plugins\platforms This application failed to start because it could not find or load the Qt platform plugin "windows".
Here is what I did:
- I used the git clone directly to get PyQt version 5.4.0
- I put this line at the very top of my script before Qt is used: import sys; import os; os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(sys._MEIPASS, 'PyQt5', 'plugins', 'platforms')
- I removed the qt.conf files from the pyinstaller dist folder
- I checked that the pyinstaller dist folder did indeed have PyQt5/plugins/platforms with a qwindows.dll in it.
I'm really desperate at this point. This worked on a Windows Server VM, but is not working on Windows 10 64-bit.
Any assistance would be greatly appreciated!
Why step 3? I think you may need a qt.conf and it needs to reside next to the executable.
Given what I said above, what paths should be in the qt.conf? That is, what are the paths in qt.conf relative to? Also, do the slashes need to be Windows-style (backslashes)? Also, is it a problem to have both the qt.conf and the env var setting line in my python code?
Ok, this is interesting. On the other Windows machine, after installing python-qt5 from git, it just worked in a python shell without any mucking with env vars or qt.conf. But on this machine, even doing the test in the original post on this thread didn't work, much less through pyinstaller.
I'm really stumped and very late on this project. Can I pay you to give me phone support or something?
Oh shit, sorry I've just head to bed over here.
There is a pretty good overview in the Qt docs about what should be in the qt.conf, but in general there should only need to be one path pointing to the main PyQt5 dir, containing all the dlls and exes. i think it was the bin path, but can't be sure and can't look it up as I'm quite indisposed at the moment.
Also its worth noting that the problem is not unique to this distribution or even PyQt, so all help on qt.conf, including that about C++, also applies here.
Also have a look at the wiki here, there's a page on updating this repo which includes a section about bundling.
Good luck and I'll try and have a look here again in the morning!
Ok, thank you!
Ok, I think I figured it out. I had to use 5.3.2, hopefully that'll work for what I need...
Phew, glad to hear it worked out. :) Don't know what the difference is between the two versions, they should be identical, but I'll keep an eye out.
setting QT_QPA_PLATFORM_PLUGIN_PATH works for me with 5.4.0
I just ran into this when using libpython embedded in another program (for the PyCall package that lets us call Python from the Julia language). Since the executable was not running from the python.exe directory (and in fact, was not running python.exe at all), it was not finding the qt.conf file.
To improve the situation for "embedded" libpython users, instead of looking at the directory of the current executable, would you consider defaulting to sys.exec_prefix? (Or is it using sys.executable now?)
(Note that on most platforms an embedding program can set sys.executable to be the location of python by calling Py_SetProgramName, but on Windows Python ignores this and always uses the name of the running program via GetModuleFileNameW. So, sys.executable is a problematic way to find qt.conf for embedded Python callers.)
Hmm, I guess this is not under PyQt's control, since the location where qt.conf is loaded is set by Qt itself.
That's right. qt.conf is entirely under the control of the Qt run-time and associated environment variables.
Unfortunately, there seems to be no environment variable to tell it an alternate location from which to load qt.conf. I filed a Qt issue so that hopefully they can improve this, but for now we are parsing qt.conf ourselves and then using it to set the QT_PLUGIN_PATH environment variable.
On a related note; I installed into a Virtualenv and had to move qt.conf from /path/to/virtualenv/ to /path/to/virtualenv/Scripts. I then updated contents to the following and it worked after that:
[Paths]
Prefix = ../Lib/site-packages/PyQt5
Binaries = ../Lib/site-packages/PyQt5