Skip to content

Troubleshooting

Storm Shadow edited this page Jul 2, 2017 · 7 revisions

This page will explain common problems and what to do when things don't work.

Qt platform plugin "windows" not found

This application failed to start because it could not find or load the Qt platform plugin "windows" Reinstalling the application may fix this problem

This is because it fails to find qwindows.dll correct in plugins\platform folder, or finds another qwindows.dll before it reaches the correct file.

Fix is to add this to user var(not system var)

QT_QPA_PLATFORM_PLUGIN_PATH=C:\Python27\lib\site-packages\PyQt5\plugins\platforms

Where

C:\Python27\lib\site-packages\PyQt5\plugins\platforms

can be the any folder where you installed PyQt5

like this

envar

Qt platform plugin "windows" not found, but QT_QPA_PLATFORM_PLUGIN_PATH is set(rare cases)

In rare cases PyQt5 cannot load the right QT_QPA_PLATFORM_PLUGIN_PATH, and uses another PATH

Example issue

Forcing the right QT_QPA_PLATFORM_PLUGIN_PATH to the app might help.

Before app is loaded, and not while loading.

insert

plugin_path = ""
if sys.platform == "win32":
    if hasattr(sys, "frozen"):
        plugin_path = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "PyQt5", "plugins")
        QCoreApplication.addLibraryPath(plugin_path)
    else:
        import site
        for dir in site.getsitepackages():
            QCoreApplication.addLibraryPath(os.path.join(dir, "PyQt5", "plugins"))

elif sys.platform == "darwin":
    plugin_path = os.path.join(QCoreApplication.getInstallPrefix(), "Resources", "plugins")

if plugin_path:
    QCoreApplication.addLibraryPath(plugin_path)

Like this

    import PyQt5
    from PyQt5 import QtCore, QtGui, uic, QtWidgets
    from PyQt5.QtWidgets import QWidget

    plugin_path = ""
    if sys.platform == "win32":
        if hasattr(sys, "frozen"):
            plugin_path = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "PyQt5", "plugins")
            QCoreApplication.addLibraryPath(plugin_path)
        else:
            import site
            for dir in site.getsitepackages():
                QCoreApplication.addLibraryPath(os.path.join(dir, "PyQt5", "plugins"))

    elif sys.platform == "darwin":
        plugin_path = os.path.join(QCoreApplication.getInstallPrefix(), "Resources", "plugins")

    if plugin_path:
        QCoreApplication.addLibraryPath(plugin_path)

Importing Qt seems to trigger this mystery issue.

4k scale error

On 4k Displays many times your PyQt5 app do not scale right, it might even be very tiny looking.

fix

Before app is loaded, and not while loading.

insert

if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
    PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)

if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
    PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

Like this

    import PyQt5
    from PyQt5 import QtCore, QtGui, uic, QtWidgets
    from PyQt5.QtWidgets import QWidget

    if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
        PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
    
    if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
        PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
    
    class MyWindow(PyQt5.QtWidgets.QMainWindow):
        def __init__(self):
            super(MyWindow, self).__init__()