【问题标题】:pyinstaller creating a standalone executable that uses qt.pypyinstaller 创建一个使用 qt.py 的独立可执行文件
【发布时间】:2020-04-01 18:33:20
【问题描述】:

我尝试使用使用 QT 的命令 pyinstaller -F helloQT.py 创建测试可执行文件,但出现以下错误:

$ ./helloQT.exe
Traceback (most recent call last):
  File "helloQT.py", line 2, in <module>
ModuleNotFoundError: No module named 'Qt'
[12884] Failed to execute script helloQT

这是我的源文件:

import sys
from Qt.QtWidgets import QApplication, QWidget, QLabel

def window():
    app = QApplication(sys.argv)
    w = QWidget()
    b = QLabel(w)
    b.setText("Hello World!")
    w.setGeometry(100, 100, 200, 50)
    b.move(50, 20)
    w.setWindowTitle("PyQt")
    w.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    window()

所以我使用 python 3.8.2 和包:

Package        Version
-------------- ---------
pip            20.0.2
PyInstaller    3.6
PySide2        5.14.2
Qt.py          1.2.5

(我还有一些其他的包,但我认为这些是相关的)

以标准方式 python helloQT.py 运行它会导致预期的执行:

我需要做些什么不同的事情才能让它正确执行?最终,我试图在 QTpy 抽象上构建一个更大的现有程序,以这种方式运行 PySide2,但我遇到了问题。我希望在攻击我的大型项目之前更好地了解这个玩具问题。

【问题讨论】:

    标签: python pyinstaller pyside2 qt.py


    【解决方案1】:

    可能PyInstaller 不知道Qt.py。虽然PySide2 被列为受支持,但Qt.py 不是。

    所以你可能不得不告诉PyInstaller 包括Qt.py。参见例如here.

    【讨论】:

    • Qt.py 与 qtpy 不同
    • 所以我按照该页面的指导运行了命令pyinstaller -F helloQT.py --hidden-import=Qt.py --debug=imports,这似乎没有改变任何东西,所以我运行了命令pyinstaller -F helloQT.py --hidden-import=Qt --debug=imports,然后给了我一个类似'AttributeError:部分初始化的错误模块'Qt'没有属性'QtGui'(很可能是由于循环导入)`我不太确定如何使用--debug=imports输出的输出来确定要放入--hidden-导入部分
    • 仔细查看 pyinstaller 的输出,我看到 7119 ERROR: Hidden import 'Qt.py' not found 行(但仅当我使用 Qt.py 时,Qt 没有此类错误
    • @eyllanesc qtpy 和 Qt.py 之间的区别是什么似乎试图解决同样的问题? pyinstaller 可以与 qtpy 一起使用吗?
    • @Jim 是有 2 个库实现了 2 种不同的方法来创建 PyQt5 和 PySide2 包装器。
    猜你喜欢
    • 1970-01-01
    • 2019-06-15
    • 2012-03-31
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    • 2013-06-01
    相关资源
    最近更新 更多