带有 --noconsole 的 Windows 上的 pyinstaller 根本不起作用

Guy*_*uyC 3 python windows wxpython pyinstaller

我有一个相当简单的 GUI (wxPython) 应用程序并且运行良好。我使用的是 Windows 7。
使用pyinstallerwith -w(or --noconsoleor --windowed)编译它并运行它时,我可以看到一个控制台窗口一毫秒,然后它关闭。GUI 应用程序将无法运行。
不使用 -w 编译将生成一个带有控制台窗口的工作应用程序。

我在这里缺少什么?

The*_*ter 8

有同样的问题。使用以下函数代替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()

Run Code Online (Sandbox Code Playgroud)

返回类型与您得到的相同Popen().communicate()[0]:) 与我的 GUI 应用程序配合得很好。使用 pyinstaller --noconsole 窗口化...

  • 莱昂,你的代码帮助我解决了我的问题。[我的 GUI 问题](/sf/ask/4292854681/)。非常感谢! (3认同)

Don*_*kby 5

我猜你会以某种方式启动一个子进程,当 Python 在没有控制台窗口的情况下运行时,它会变得一团糟。我不得不解决与此相关的三个问题:

  1. multiprocessing模块在产生工作进程时需要设置一个环境变量
  2. subprocess模块需要明确的处理 stdinstdoutstderr,因为标准的文件句柄不为子进程继承设置。
  3. 子进程会创建一个控制台窗口,除非您告诉它不要这样做