Ondrej Vencovsky
Ondrej Vencovsky

Reputation: 3508

PyQt5 - Failed to load platform plugin "windows". Available platforms are: windows, minimal

When I try to run any PyQt5 program from Eclipse, I got this error.

Failed to load platform plugin "windows". Available platforms are: windows, minimal

I've never encountered this problem with PyQt4 but with the new version.

I'm not able to run a program. From other questions here I know it happens with Qt C++ development and the solution is to copy some Qt dll files to executable program directory.

Do I need to do the same in Python development (PyQt5) too? Add those files to the directory, where my *.py files reside? Shouldn't this be managed by PyQt5 installation?

Thank you

Upvotes: 9

Views: 23936

Answers (8)

chatzich
chatzich

Reputation: 1133

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"))

Upvotes: 0

AndreBam_
AndreBam_

Reputation: 21

This is what worked for me while using the Anaconda Python 3.6 distribution:

  1. I installed PyQt5 using pip install pyqt5. What this does is it creates a Qt/Pluginsplugins directory in the ../Anaconda3/Lib/site-packages/PyQt5 path.

  2. Following Roger Allen and uetoyo, I added:

if os.name == "nt":  # if windows
    from PyQt5 import __file__
    pyqt_plugins = os.path.join(os.path.dirname(__file__), "Qt", "plugins")
    QApplication.addLibraryPath(pyqt_plugins)
    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = pyqt_plugins

to my script. It works with pyinstaller as well.

Upvotes: 0

Roger Allen
Roger Allen

Reputation: 2312

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)

Upvotes: 1

Fakh.P
Fakh.P

Reputation: 51

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

Upvotes: 5

uetoyo
uetoyo

Reputation: 329

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!

Upvotes: 4

Calvin Smythe
Calvin Smythe

Reputation: 201

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.

Upvotes: 1

Babken Vardanyan
Babken Vardanyan

Reputation: 15090

Copy C:\Python34\Lib\site-packages\PyQt5\libEGL.dll to the same directory as your .exe.

Source: http://bird1110.blogspot.com/2014/04/python-33-pyqt5-and-cxfreeze-exe-on-64.html

Upvotes: 7

Arun M
Arun M

Reputation: 1452

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"

Upvotes: 11

Related Questions