Python Pyinstaller创建了Pyside2脚本的exe文件
我有一个奇怪的问题。我创建了一个Python脚本,它使用自定义股票交易算法向用户发出买入和卖出信号 我在GUI工具包中使用了PySide2,但Tkinter也有同样的问题 首先,以下是我的代码的相关片段:Python Pyinstaller创建了Pyside2脚本的exe文件,python,pyinstaller,pyside2,Python,Pyinstaller,Pyside2,我有一个奇怪的问题。我创建了一个Python脚本,它使用自定义股票交易算法向用户发出买入和卖出信号 我在GUI工具包中使用了PySide2,但Tkinter也有同样的问题 首先,以下是我的代码的相关片段: 主窗口 打开子窗口以查看单个票据 类ScripWindow(QMainWindow): 定义初始(自我、父母、票据信息): QMainWindow.\uuuu init\uuuuu(自,父) ... ... 创建和添加GUI小部件 ... ... self.\u scrip\u queue=q
类ScripWindow(QMainWindow):
定义初始(自我、父母、票据信息):
QMainWindow.\uuuu init\uuuuu(自,父)
...
...
创建和添加GUI小部件
...
...
self.\u scrip\u queue=queue()
self.\u scrip\u algo=ScripAlgo(self.\u scrip\u队列)
self.\u scrip\u algo\u进程=进程(目标=self.\u scrip\u algo.run\u algo)
self.\u scrip\u algo\u process.start()我找到了答案
似乎您必须在脚本开始时调用multiprocessing.freeze_support(),才能使其作为.exe文件在Windows上正确运行(如果您在脚本中使用multiprocessing,也就是说)
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
...
...
Create and add GUI widgets
...
...
watch_button = QPushButton("Watch")
watch_button.clicked.connect(self.watch_scrip)
@Slot()
def watch_scrip(self, checked):
ScripWindow(self, ScripInfo(self._scrips_strings[self._scrip_list.currentIndex()])).show()
def closeEvent(self, event):
QApplication.closeAllWindows()
event.accept()
class ScripWindow(QMainWindow):
def __init__(self, parent, scrip_info):
QMainWindow.__init__(self, parent)
...
...
Create and add GUI widgets
...
...
self._scrip_queue = Queue()
self._scrip_algo = ScripAlgo(self._scrip_queue)
self._scrip_algo_process = Process(target=self._scrip_algo.run_algo)
self._scrip_algo_process.start() <-- Start algorithm in a new background process which writes to Queue
QTimer.singleShot(1000, self._process_queue)
def _process_queue(self):
while not self._scrip_queue.empty():
data_string = self._scrip_queue.get()
...
...
Read and display data from the Queue object generated by algorithm
...
...
QTimer.singleShot(1000, self._process_queue)
def closeEvent(self, event):
self._scrip_algo_process.terminate()
event.accept()