1

我使用. Qt_ 当我通过python运行python文件时,没问题。当我尝试将项目转换为可执行文件时,它失败了。我遇到了很多问题,我在谷歌中解决了这些问题。但是,我找不到 belove fail 的解决方案。python 3.8PyQt6

此应用程序无法启动,因为无法初始化 QT 平台插件。重新安装应用程序可能会解决此问题

我用auto-py-to-exebelove 命令创建可执行文件

pyinstaller --noconfirm --onedir --windowed --icon "D:/WorkSpace/Projects/MouseReplayer/output/icon/icon2.ico" --name "Auto Test Repeater" --add-data "D:/WorkSpace/Projects/MouseReplayer/ScreenCopy;ScreenCopy/"
--add-data "D:/WorkSpace/Projects/MouseReplayer/ui;ui/" --paths "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/bin"
--hidden-import "PyQt6.sip"  "D:/WorkSpace/Projects/MouseReplayer/ui_main.py"

我尝试重新安装但没有成功。实际上,这个问题在 Youtube 中很常见,PyQt5根据 Youtube 的说法,有一个简单的解决方案(Youtube 解决方案)将平台文件夹(PyQt5\Qt\plugins\platforms)复制到Pyqt5-tools文件夹中,全部在Python\Python38\Lib\site-packages. 但是,互联网上没有Pyqt6-tools文件夹,site-packages也没有安装指南。

我需要帮助解决它或找到另一种方法来创建兼容的可执行文件PyQt6

4

1 回答 1

1

Copying dll files in Python\Python38\Lib\site-packages\PyQt5\Qt\plugins\platformsinto directly executable output folder is solved the issue. My recent pyinstaller command that:

pyinstaller --noconfirm --onedir --windowed --icon "D:/WorkSpace/Projects/MouseReplayer/output/icon2.ico" --name "Auto Test Player" --add-data "D:/WorkSpace/Projects/MouseReplayer/ScreenCopy;ScreenCopy/" --add-data "D:/WorkSpace/Projects/MouseReplayer/ui;ui/" --paths "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/bin" --hidden-import "PyQt6.sip" --hidden-import "PyQt6.QtPrintSupport" --add-data "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/plugins/platforms;platforms/"  "D:/WorkSpace/Projects/MouseReplayer/ui_main.py"

key line to fix is that:

--add-data "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/plugins/platforms;platforms/" 

and also below line is to prevent another issue:

--hidden-import "PyQt6.sip"

may be this one also important:

--hidden-import "PyQt6.QtPrintSupport"
于 2021-02-20T00:52:37.007 回答