[英]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:
我不得不解决与此有关的三个问题:
multiprocessing
module needs to set an environment variable when it spawns worker processes. multiprocessing
模块在生成工作进程时需要设置环境变量 。 subprocess
module needs to explicitly handle stdin
, stdout
, and stderr
, because the standard file handles aren't set for subprocesses to inherit. subprocess
模块需要显式处理 stdin
, stdout
和stderr
,因为没有为子流程继承设置标准文件句柄。 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.