我正在尝试使用py2exe将PyQt py编译为exe 导入系统 来自PyQt5导入QtWidgets
#PythonApplication1.py
def main():
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
button = QtWidgets.QPushButton("Hello world")
window.setCentralWidget(button)
window.show()
app.exec_()
-
#setup.py
from distutils.core import setup
import py2exe
setup(windows=[{"script":"PythonApplication1.py"}], options={"py2exe":{"includes":["sip"]}})
$ python setup.py py2exe - 包含sip
当我运行exe时,只有错误窗口:有关详细信息,请参阅日志文件'C:\ dist \ PythonApplication1.log'。
#PythonApplication1.log
Traceback (most recent call last):
File "PythonApplication1.py", line 5, in <module>
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (No module named 'PyQt5.QtCore') 'C:\\dist\\PyQt5.QtWidgets.pyd'
答案 0 :(得分:1)
我设法通过修改 setup.py
来构建可执行应用程序setup(windows=[{"script": "PythonApplication1.py"}],
options= {"py2exe": {"includes": ["sip", "PyQt5.QtCore", "PyQt5.QtGui"]}})
并将 qwindows.dll 复制到 dist / platforms / 目录。
另一种方法是添加导入语句
import PyQt5.QtCore
import PyQt5.QtGui
到主程序。