带有 --noconsole 的 Windows 上的 pyinstaller 根本不起作用 [英] pyinstaller on Windows with --noconsole simply won't work
问题描述
我有一个相当简单的 GUI (wxPython) 应用程序并且运行良好.我使用的是 Windows 7.
使用 pyinstaller
和 -w
(或 --noconsole
或 --windowed
)编译并运行它时,我可以看到一个控制台窗口一毫秒,然后它关闭.GUI 应用程序将无法运行.
不使用 -w 编译将生成一个带有控制台窗口的工作应用程序.
I have a fairly simple GUI (wxPython) app and is working great. I'm using 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. The GUI app won't run.
Compiling without the -w will produce a working app with a console window.
我在这里遗漏了什么?
推荐答案
我猜你是在以某种方式启动一个子进程,当 Python 在没有控制台窗口的情况下运行时,它会变得一团糟.我必须解决与此相关的三个问题:
I would guess that you are somehow launching a subprocess that gets messed up when Python runs without a console window. I have had to solve three problems related to this:
multiprocessing
模块需要设置环境变量 当它产生工作进程时.subprocess
模块需要明确处理stdin
,stdout
和stderr
,因为没有为要继承的子进程设置标准文件句柄.- 子进程会创建一个控制台窗口,除非您告诉它不要.
- The
multiprocessing
module needs to set an environment variable when it spawns worker processes. - The
subprocess
module needs to explicitly handlestdin
,stdout
, andstderr
, because the standard file handles aren't set for subprocesses to inherit. - The subprocess creates a console window, unless you tell it not to.
这篇关于带有 --noconsole 的 Windows 上的 pyinstaller 根本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!