When I try to run any PyQt5 program from Eclipse, I got this error.
Failed to load platform plugin \"windows\". Available platforms are: windows, mini
I like uetoyo's answer, but Anaconda has moved the directory. This works for me Python 3.5.2 Anaconda 4.2.0 on Windows 7.
import os
if os.name == "nt": # if windows
import PyQt5
pyqt_plugins = os.path.join(os.path.dirname(PyQt5.__file__),
"..", "..", "..", "Library", "plugins")
QApplication.addLibraryPath(pyqt_plugins)
if you use PySide2 you can check with this
import os
if os.name == 'nt':
import PySide2
pyqt = os.path.dirname(PySide2.__file__)
QApplication.addLibraryPath(os.path.join(pyqt, "plugins"))
I encountered this issue with PyQt5 5.0.2, Windows 8, Python 3.3.2; slightly different error message:
Failed to load platform plugin "windows". Available platforms are:
Set the following environment variable and then run the application.
$env:QT_QPA_PLATFORM_PLUGIN_PATH="C:\Python33\Lib\site-packages\PyQt5\plugins\platforms"
i had a similar problem when compiling my code with cx_freeze
.
Copying the folder platforms from python installation directory into my built folder solved the problem. the "platforms" folder contains qminimal.dll
I found the file: qwindows.dll needed to be included to allow my .exe file to run independently without getting the error. To do so, add the qwindows.dll path to your data files list:
setup(windows=[YOURSCRIPT.py]
, data_files = [('.','DRIVE:\PythonPath\Lib\site-packages\PyQt4\plugings\platforms\qwindows.dll')])
The reason you would do this and now set your environment path is that your program will run on any machine if the qwindows.dll file is held in the same package. If you only set the environment variable, the program will only successfully run on a computer with PyQt installed.
Another solution which works for me; Windows 7; PyQt5, Python 3.4 64bit:
pyqt = os.path.dirname(PyQt5.__file__)
QApplication.addLibraryPath(os.path.join(pyqt, "plugins"))
You can also set an environment variable QT_QPA_PLATFORM_PLUGIN_PATH
with the path to the plugins
directory.
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = qt_platform_plugins_path
This also works very well with PyInstaller!