pyqt5 - pyinstaller打包的程序运行时崩溃
问题描述
我尝试用pyqt5创建一个命令行程序,并使用pyinstaller对其进行打包。我的打包命令是:pyinstaller --windowed --onefile main.py
但是,输入命令运行后,我的程序崩溃了
如果我使用pyinstaller --windowed main.py
或pyinstaller --onefile main.py
程序仍然有效
这是代码:
主文件
import sys
import os
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QPlainTextEdit, QHBoxLayout, QVBoxLayout
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.window_width, self.window_height = 1200, 1500
self.setMinimumSize(self.window_width, self.window_height)
self.setWindowTitle('Command Line App')
layout = QVBoxLayout()
self.setLayout(layout)
self.editorCommand = QPlainTextEdit()
layout.addWidget(self.editorCommand, 3)
self.editorOutput = QPlainTextEdit()
layout.addWidget(self.editorOutput, 7)
buttonLayout = QHBoxLayout()
layout.addLayout(buttonLayout)
self.button_run = QPushButton('&Run Command', clicked=self.runCommand)
buttonLayout.addWidget(self.button_run)
self.button_clear = QPushButton('&Clear', clicked=lambda: self.editorOutput.clear())
buttonLayout.addWidget(self.button_clear)
self.editorCommand.insertPlainText('dir')
def runCommand(self):
command_line = self.editorCommand.toPlainText().strip()
p = os.popen(command_line)
if p:
self.editorOutput.clear()
output = p.read()
self.editorOutput.insertPlainText(output)
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyleSheet('''
QWidget {
font-size: 30px;
}
''')
myApp = MyApp()
myApp.show()
try:
sys.exit(app.exec_())
except SystemExit:
print('Closing Window...')
解决方案
尝试以这种方式运行 PyInstaller:
pyinstaller -F -w my_file.py
推荐阅读
- java - 我的代码中出现运行时错误。当我输入字母时,只有布尔有效值变为真
- c# - 使用 Collider2D.IsTouchingLayers 检测运动学刚体与静态刚体的碰撞
- ubuntu - Perforce安装,客户端未知
- python - 在python 3中结合while和if else
- excel - 无法识别的数据库格式(opendatabase 错误)
- mysql - mysql 5.7(percona)上的慢速删除表
- dart - Dart 的 HttpRequest 中的“进度事件”错误是什么?
- ios - 我的 Alembic 文件 (.abc) 中的模型具有扁平的节点层次结构,并且在 iOS 中缺少面孔
- java - 通过 Scanner 类获取字符输入
- git - 如何防止 Git 自动检测 user.email?