创建 PyQt6 Python 项目可执行文件
Create PyQt6 Python Project Executable
我使用 PyQt6
在 python 3.8
中编写了一个 Qt
项目。当我 运行 python 文件按 python 时,没问题。当我尝试将项目转换为可执行文件时,它失败了。我遇到了很多问题,我在 google 中解决了它们。但是我找不到 belove 失败的解决方案。
This application failed to start because no QT platform plugin could
be initialized. Reinstalling the application may fix this problem
我使用 auto-py-to-exe
通过 belove 命令创建可执行文件
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"
我尝试重新安装但没有成功。实际上,这个问题在 PyQt5
中很常见,根据 Youtube,有一个简单的解决方案(Youtube Solution)将平台文件夹(PyQt5\Qt\plugins\platforms
)复制到 Pyqt5-tools
文件夹中, 都在 Python\Python38\Lib\site-packages
中。但是 site-packages
中没有 Pyqt6-tools
文件夹,互联网上也没有安装指南。
我需要帮助解决它或找到另一种方法来创建与 PyQt6
兼容的可执行文件
将 Python\Python38\Lib\site-packages\PyQt5\Qt\plugins\platforms
中的 dll 文件复制到直接可执行的输出文件夹中解决了这个问题。我最近的 pyinstaller 命令是:
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"
要修复的关键行是:
--add-data "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/plugins/platforms;platforms/"
下面一行是为了防止另一个问题:
--hidden-import "PyQt6.sip"
可能这个也很重要:
--hidden-import "PyQt6.QtPrintSupport"
我使用 PyQt6
在 python 3.8
中编写了一个 Qt
项目。当我 运行 python 文件按 python 时,没问题。当我尝试将项目转换为可执行文件时,它失败了。我遇到了很多问题,我在 google 中解决了它们。但是我找不到 belove 失败的解决方案。
This application failed to start because no QT platform plugin could be initialized. Reinstalling the application may fix this problem
我使用 auto-py-to-exe
通过 belove 命令创建可执行文件
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"
我尝试重新安装但没有成功。实际上,这个问题在 PyQt5
中很常见,根据 Youtube,有一个简单的解决方案(Youtube Solution)将平台文件夹(PyQt5\Qt\plugins\platforms
)复制到 Pyqt5-tools
文件夹中, 都在 Python\Python38\Lib\site-packages
中。但是 site-packages
中没有 Pyqt6-tools
文件夹,互联网上也没有安装指南。
我需要帮助解决它或找到另一种方法来创建与 PyQt6
将 Python\Python38\Lib\site-packages\PyQt5\Qt\plugins\platforms
中的 dll 文件复制到直接可执行的输出文件夹中解决了这个问题。我最近的 pyinstaller 命令是:
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"
要修复的关键行是:
--add-data "C:/Users/26010693/AppData/Local/Programs/Python/Python38/Lib/site-packages/PyQt6/Qt/plugins/platforms;platforms/"
下面一行是为了防止另一个问题:
--hidden-import "PyQt6.sip"
可能这个也很重要:
--hidden-import "PyQt6.QtPrintSupport"