Windows上带有--noconsole的pyinstaller根本无法工作

问题描述 投票:3回答:2

我有一个非常简单的GUI(wxPython)应用程序,并且运行良好。我正在使用Windows 7。使用pyinstaller-w(或--noconsole--windowed)编译并运行它时,我可以看到一个控制台窗口,显示时间为毫秒,然后将其关闭。 GUI应用程序将无法运行。不使用-w进行编译将产生带有控制台窗口的可运行应用程序。

我在这里想念什么?

python windows wxpython pyinstaller
2个回答
3
投票

我想您正在以某种方式启动一个子进程,当Python在没有控制台窗口的情况下运行时,该子进程会陷入混乱。我不得不解决与此有关的三个问题:

  1. multiprocessing模块在生成工作进程时需要set an environment variable
  2. subprocess模块需要explicitly handle stdinstdoutstderr,因为没有为子进程继承设置标准文件句柄。
  3. 子进程将创建一个控制台窗口,除非您tell it not to

0
投票

有相同的问题。使用以下功能代替subprocess.Popen()

def popen(cmd):
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    process = subprocess.Popen(cmd, startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    return process.stdout.read()

返回类型与您从Popen().communicate()[0]中获得的返回类型相同:)非常适合我的GUI应用程序。用pyinstaller窗口--noconsole ...

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