我為 dj 自動化做了一個小程式。
編碼:
#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)
如果您使用 pyinstaller 編譯上述腳本,運行它一切正常(mixxx.exe 正確打開)。但是,如果您取消注釋第一個匯入行,那么在嘗試運行它時會發生此錯誤:
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.
如果我不使用輸出: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.
似乎 PyQt5 匯入會影響 pywinauto 啟動或使用 C qt 撰寫的 Mixx 程式。
出了什么問題,我該如何解決?
只有在 pyinstaller 編譯后問題才存在。
請注意,如果我使用此代碼創建 .exe:
from PyQt5 import QtCore, QtGui, QtWidgets
或者使用從 Qt Designer 創建的 pyuic5 py 檔案沒有錯誤。
該錯誤僅在我匯入 PyQt5 然后嘗試打開 mixx (pyinstaller) 時存在。如果我匯入 PyQt5 然后嘗試打開另一個像 calc 這樣的應用程式沒有問題......
uj5u.com熱心網友回復:
實際問題是 Qt C (mixxx) 的平臺插件被 PyInstaller 干擾了 PyQt5 初始化。
通過擴展解決了這個問題:
Popen(r'C:\Program Files\Mixxx\mixxx.exe')
有了這個:
Popen(r'C:\Program Files\Mixxx\mixxx.exe', env=dict(os.environ, QT_PLUGIN_PATH=''))
此更改存盤QT_PLUGIN_PATH正確的值 ( '')。
感謝@relent95,因為他是問題的解決者。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/517394.html
