0

I have made a small program for dj automation.

The code:

#from PyQt5 import QtCore, QtGui, QtWidgets
from pywinauto.application import Application as PyWinAutoApplication
from subprocess import Popen
import time
import os

os.environ["QT_DEBUG_PLUGINS"] = "1"

#Open mixxx
Popen(r'C:\Program Files\Mixxx\mixxx.exe')
#time.sleep(5)
#mixxx_app = PyWinAutoApplication(backend="uia").connect(title="Mixxx")
while(True):
    time.sleep(10)

if you compile the above script with pyinstaller the run it everything works good (mixxx.exe is opening correctly). But if you uncomment the first import line then when trying to run it this error happens:

QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qminimal.dll"
Found metadata in lib C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qminimal.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "archreq": 0,
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qoffscreen.dll"
Found metadata in lib C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qoffscreen.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "archreq": 0,
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qwebgl.dll"
Found metadata in lib C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qwebgl.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "webgl"
        ]
    },
    "archreq": 0,
    "className": "QWebGLIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("webgl")
QFactoryLoader::QFactoryLoader() looking at "C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qwindows.dll"
Found metadata in lib C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qwindows.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "windows"
        ]
    },
    "archreq": 0,
    "className": "QWindowsIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("windows")
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "C:/Program Files/Mixxx/plugins/platforms/qwindows.dll"
Found metadata in lib C:/Program Files/Mixxx/plugins/platforms/qwindows.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "windows"
        ]
    },
    "archreq": 0,
    "className": "QWindowsIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("windows")
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/platforms" ...
Cannot load library C:\Users\cpapp\OneDrive\???????????\dist\py_error_1\PyQt5\Qt5\plugins\platforms\qwindows.dll: The specified procedure could not be found.
QLibraryPrivate::loadPlugin failed on "C:/Users/cpapp/OneDrive/???????????/dist/py_error_1/PyQt5/Qt5/plugins/platforms/qwindows.dll" : "Cannot load library C:\\Users\\cpapp\\OneDrive\\???????????\\dist\\py_error_1\\PyQt5\\Qt5\\plugins\\platforms\\qwindows.dll: The specified procedure could not be found."
qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: minimal, offscreen, webgl, windows.

The output if I don't use: from PyQt5 import QtCore,QtGui,QtWidgets

C:\Users\cpapp\OneDrive\Υπολογιστής\dist\py_error_1>py_error_1.exe
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "C:/Program Files/Mixxx/plugins/platforms/qwindows.dll"
Found metadata in lib C:/Program Files/Mixxx/plugins/platforms/qwindows.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "windows"
        ]
    },
    "archreq": 0,
    "className": "QWindowsIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("windows")
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/platforms" ...
loaded library "C:/Program Files/Mixxx/plugins/platforms/qwindows.dll"
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/plugins/platformthemes" ...
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/platformthemes" ...
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/plugins/styles" ...
QFactoryLoader::QFactoryLoader() looking at "C:/Program Files/Mixxx/plugins/styles/qwindowsvistastyle.dll"
Found metadata in lib C:/Program Files/Mixxx/plugins/styles/qwindowsvistastyle.dll, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "windowsvista"
        ]
    },
    "archreq": 0,
    "className": "QWindowsVistaStylePlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("windowsvista")
QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/styles" ...
loaded library "C:/Program Files/Mixxx/plugins/styles/qwindowsvistastyle.dll"
Warning [Main]: Failed to load "mixxx" translations for locale "el_GR" from "C:/Program Files/Mixxx/translations/"
Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/iconengines/qsvgicon.dll, metadata=
{
    "IID": "org.qt-project.Qt.QIconEngineFactoryInterface",
    "MetaData": {
        "Keys": [
            "svg",
            "svgz",
            "svg.gz"
        ]
    },
    "archreq": 0,
    "className": "QSvgIconPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qgif.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "gif"
        ],
        "MimeTypes": [
            "image/gif"
        ]
    },
    "archreq": 0,
    "className": "QGifPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qicns.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "icns"
        ],
        "MimeTypes": [
            "image/x-icns"
        ]
    },
    "archreq": 0,
    "className": "QICNSPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qico.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "ico",
            "cur"
        ],
        "MimeTypes": [
            "image/vnd.microsoft.icon",
            "image/vnd.microsoft.icon"
        ]
    },
    "archreq": 0,
    "className": "QICOPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qjp2.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "jp2"
        ],
        "MimeTypes": [
            "image/jp2",
            "image/jpx",
            "image/jpm",
            "video/mj2"
        ]
    },
    "archreq": 0,
    "className": "QJp2Plugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qjpeg.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "jpg",
            "jpeg"
        ],
        "MimeTypes": [
            "image/jpeg",
            "image/jpeg"
        ]
    },
    "archreq": 0,
    "className": "QJpegPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qsvg.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "svg",
            "svgz"
        ],
        "MimeTypes": [
            "image/svg+xml",
            "image/svg+xml-compressed"
        ]
    },
    "archreq": 0,
    "className": "QSvgPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qtga.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "tga"
        ],
        "MimeTypes": [
            "image/x-tga"
        ]
    },
    "archreq": 0,
    "className": "QTgaPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qtiff.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "tiff",
            "tif"
        ],
        "MimeTypes": [
            "image/tiff",
            "image/tiff"
        ]
    },
    "archreq": 0,
    "className": "QTiffPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qwbmp.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "wbmp"
        ],
        "MimeTypes": [
            "image/vnd.wap.wbmp"
        ]
    },
    "archreq": 0,
    "className": "QWbmpPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/imageformats/qwebp.dll, metadata=
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "webp"
        ],
        "MimeTypes": [
            "image/webp"
        ]
    },
    "archreq": 0,
    "className": "QWebpPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/sqldrivers/qsqlite.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QSQLITE"
        ]
    },
    "archreq": 0,
    "className": "QSQLiteDriverPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/sqldrivers/qsqlodbc.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QODBC3",
            "QODBC"
        ]
    },
    "archreq": 0,
    "className": "QODBCDriverPlugin",
    "debug": false,
    "version": 331520
}


Warning [Main]: Found metadata in lib C:/Program Files/Mixxx/plugins/sqldrivers/qsqlpsql.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QPSQL7",
            "QPSQL"
        ]
    },
    "archreq": 0,
    "className": "QPSQLDriverPlugin",
    "debug": false,
    "version": 331520
}


Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.
Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.
Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.
Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.
Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.
Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.
Warning [Controller]: USB permissions problem (or device error.) Your account needs write access to USB HID controllers.

It seems that PyQt5 imports are affect pywinauto start or Mixx program which is writter in C++ qt.

What's wrong and how can i fix it?

The problem exists only after pyinstaller compilation.

Note that if i create an .exe with this code:

from PyQt5 import QtCore, QtGui, QtWidgets

or with an pyuic5 py file created from Qt Designer there is no error.

The error exists only when i import PyQt5 and then try to open mixx (pyinstaller). If i import PyQt5 and then try to open another app like calc there is no problem...

Chris P
  • 2,059
  • 4
  • 34
  • 68
  • I strongly doubt it's an issue with the program, more probably it's with PyWinAuto, which probably detects a Qt import and tries to behave accordingly. Add some prints to check where exactly the error appears. Also, use a variable for the Popen object. – musicamante Oct 15 '22 at 07:33
  • See [this](https://stackoverflow.com/questions/48007100/error-could-not-find-or-load-the-qt-platform-plugin-windows-pyqt-pyinstal). It's not related to the pywinauto and mixxx. – relent95 Oct 15 '22 at 09:04
  • @relent95 That's an approximate assumption. The OP has already used [Py]Qt, and UI automation libraries such as pywinauto *do* need to know about existing event loop managers in order to work with them as expected. – musicamante Oct 15 '22 at 23:26
  • @ChrisP I believe that the real questions are: why do you need those Qt imports? Do you need to interact with Mixx? Did you consider to spawn a separate process that runs the pywinauto manager along with the Mixx app, and then interact with it using piping (stdin/stdout)? – musicamante Oct 15 '22 at 23:31
  • The error is related to this: `QFactoryLoader::QFactoryLoader() checking directory path "C:/Program Files/Mixxx/plugins/platforms" ...` but why is also checking this directory? – Chris P Oct 15 '22 at 23:51
  • 1
    The log you added is the output of the child process(mixxx.exe), not the main executable generated by PyInstaller. This is caused by environment variables set by PyInstaller module in the main executable. So, try this, ```Popen(r'C:\Program Files\Mixxx\mixxx.exe', env=dict(os.environ, QT_PLUGIN_PATH=''))``` – relent95 Oct 16 '22 at 02:24
  • @relent95 Yes this was the fix. Post an answer to accept it. – Chris P Oct 16 '22 at 12:12
  • What about answering your own question? You can have my credit. – relent95 Oct 16 '22 at 13:10

1 Answers1

0

The actual problem was that platforms plugin of Qt C++ (mixxx) was interfered with PyQt5 initialization by PyInstaller.

The problem was solved by extending:

Popen(r'C:\Program Files\Mixxx\mixxx.exe')

with this:

Popen(r'C:\Program Files\Mixxx\mixxx.exe', env=dict(os.environ, QT_PLUGIN_PATH=''))

This change stores QT_PLUGIN_PATH the right value ('').

Thanks to @relent95 because he was the solver of the problem.

Chris P
  • 2,059
  • 4
  • 34
  • 68
  • Good job. But the explanation on the cause is incorrect. What about changing to "... platforms plugin of Qt C++ (mixxx) was interfered with PyQt5 initialization by PyInstaller"? – relent95 Oct 18 '22 at 15:12