python - 创建 PyQt6 Python 项目可执行文件
问题描述
我使用. Qt
_ 当我通过python运行python文件时,没问题。当我尝试将项目转换为可执行文件时,它失败了。我遇到了很多问题,我在谷歌中解决了这些问题。但是,我找不到 belove fail 的解决方案。python 3.8
PyQt6
此应用程序无法启动,因为无法初始化 QT 平台插件。重新安装应用程序可能会解决此问题
我用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"
我尝试重新安装但没有成功。实际上,这个问题在 Youtube 中很常见,PyQt5
根据 Youtube 的说法,有一个简单的解决方案(Youtube 解决方案)将平台文件夹(PyQt5\Qt\plugins\platforms
)复制到Pyqt5-tools
文件夹中,全部在Python\Python38\Lib\site-packages
. 但是,互联网上没有Pyqt6-tools
文件夹,site-packages
也没有安装指南。
我需要帮助解决它或找到另一种方法来创建兼容的可执行文件PyQt6
解决方案
Copying dll files in Python\Python38\Lib\site-packages\PyQt5\Qt\plugins\platforms
into 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"
推荐阅读
- python - 获取属性错误:模块“熊猫”没有属性“json_normalize”
- php - 带标题的强制文件下载会损坏文件
- javascript - html datalist 选项在空白处消失
- r - 使用 fviz_clust 显示所有标签
- javascript - 使用 Typescript 的 Nodejs 中的导入语句在编译后无法使用绝对路径解析
- android - 如何使用 Jetpack Compose 将片段添加到 Activity
- php - Eloquent::where() 条件未按预期工作,但 Collection::where() 确实有效
- openfeign - Feign客户端自定义请求对象有一个枚举字段,传递给服务时,这个枚举字段为空
- flutter - Android Studio 上的新 Flutter 项目
- angular - 如何在顶点柱形图中重新定位工具提示?