Pyinstaller“无法脚本执行主脚本”问题

时间:2019-09-15 13:24:12

标签: python pyqt5 pyinstaller

编辑:Python 3.7.4,Windows 10

Edit2:我找到了错误的原因。输出:

Traceback (most recent call last):
 File "myMain.py", line 2, in <module>
 File "c:\users\faruk\appdata\local\programs\python\python37\lib\site- 
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
 File "site-packages\PyQt5\__init__.py", line 41, in <module>
 File "site-packages\PyQt5\__init__.py", line 33, in find_qt
ImportError: unable to find Qt5Core.dll on PATH
[13936] Failed to execute script myMain

以下是解决方法:https://stackoverflow.com/a/56962128/9377945

我正在尝试使用pyinstaller将py文件转换为exe。

我的示例代码在这里:

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize    

class HelloWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(640, 480))    
        self.setWindowTitle("Hello world") 

        centralWidget = QWidget(self)          
        self.setCentralWidget(centralWidget)   

        gridLayout = QGridLayout(self)     
        centralWidget.setLayout(gridLayout)  

        title = QLabel("Hello World", self) 
        title.setAlignment(QtCore.Qt.AlignCenter) 
        gridLayout.addWidget(title, 0, 0)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = HelloWindow()
    mainWin.show()
    sys.exit( app.exec_() )

我使用以下代码进行转换:

pyinstaller main.py --noconsole

当我尝试运行exe文件时,出现“无法执行脚本主程序”错误。

2 个答案:

答案 0 :(得分:0)

您安装了那些软件包吗?如果您使用的是IDE进行编码,则还必须在系统中安装软件包

答案 1 :(得分:0)

删除pyinstaller和PyQt5,然后使用 pip3

安装它们
pip3 install pyinstaller   
pip3 install PyQt5