Pyinstaller创建的Pyside2脚本exe文件

问题描述 投票:0回答:1

我有一个奇怪的问题。我创建了一个Python脚本,该脚本使用自定义的股票交易算法向用户提供购买和出售信号。

我已经将PySide2用于GUI工具包,但是Tkinter也遇到了同样的问题。

首先,这是我的代码的相关摘要:

  1. 主窗口
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()
  1. 子窗口打开以供观看单个脚本
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()

该脚本通过Python完美运行。即使“ pythonw my_app.pyw”也可以在没有控制台的情况下运行。

当我使用Pyinstaller创建.exe文件时出现问题。当我运行.exe文件时,它将打开MainWindow。当我按下“监视”按钮时,它会像预期的那样打开一个子窗口(ScripWindow)。但这也会打开另一个主窗口。

可能是什么问题?以及如何解决?

提前感谢。

python pyinstaller pyside2
1个回答
0
投票

我找到了答案at this link

似乎您必须在脚本的开头调用multiprocessing.freeze_support()才能使其以.exe文件的形式在Windows上正常运行(如果在脚本中使用了多处理功能,则是]

© www.soinside.com 2019 - 2024. All rights reserved.