pyinstaller创建一个使用qt.py的独立可执行文件

时间:2020-04-01 18:33:20

标签: python pyinstaller pyside2 qt.py

我尝试使用使用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运行它会导致预期的执行:

enter image description here

我需要做些什么才能使其正确执行?最终,我试图在基于QTpy的PySide2抽象上获得一个更大的现有程序,以这种方式运行,但是我遇到了问题。我的希望是在攻击我的较大项目之前更好地了解这个玩具问题。

1 个答案:

答案 0 :(得分:1)

PyInstaller可能不了解Qt.py。虽然PySide2被列为受支持,但Qt.py却不受支持。

因此,您可能必须告诉PyInstaller包含Qt.py。参见例如here

相关问题