简体   繁体   English

带有--noconsole的Windows上的pyinstaller无法正常工作

[英]pyinstaller on Windows with --noconsole simply won't work

I have a fairly simple GUI (wxPython) app and is working great. 我有一个相当简单的GUI(wxPython)应用程序,并且运行良好。 I'm using Windows 7. 我正在使用Windows 7。
When compiling it using pyinstaller with -w (or --noconsole or --windowed ) and run it, I can see a console window for a millisecond and then it shutdown. 当使用带有-w (或--noconsole--windowed )的pyinstaller编译它并运行它时,我可以看到一个控制台窗口达一毫秒,然后将其关闭。 The GUI app won't run. GUI应用程序将无法运行。
Compiling without the -w will produce a working app with a console window. 不使用-w进行编译将产生带有控制台窗口的可运行应用程序。

What am I missing here? 我在这里想念什么?

I would guess that you are somehow launching a subprocess that gets messed up when Python runs without a console window. 我猜想您正在以某种方式启动一个子进程,当Python在没有控制台窗口的情况下运行时,该子进程会陷入混乱。 I have had to solve three problems related to this: 我不得不解决与此有关的三个问题:

  1. The multiprocessing module needs to set an environment variable when it spawns worker processes. multiprocessing模块在生成工作进程时需要设置环境变量
  2. The subprocess module needs to explicitly handle stdin , stdout , and stderr , because the standard file handles aren't set for subprocesses to inherit. subprocess模块需要显式处理 stdinstdoutstderr ,因为没有为子流程继承设置标准文件句柄。
  3. The subprocess creates a console window, unless you tell it not to . 子进程将创建一个控制台窗口,除非您不告诉它

Had the same problem. 有同样的问题。 Used the following function instead of subprocess.Popen() : 使用以下函数代替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()

the return type is the same as you would get from Popen().communicate()[0] :) Works great with my GUI application. 返回类型与您从Popen().communicate()[0] :)获得的返回类型相同:)非常适合我的GUI应用程序。 Windowed with pyinstaller --noconsole... 用pyinstaller窗口--noconsole ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM