问题
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.
What am I missing here?
回答1:
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:
- The
multiprocessingmodule needs to set an environment variable when it spawns worker processes. - The
subprocessmodule 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.
回答2:
Had the same problem. Used the following function instead of 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. Windowed with pyinstaller --noconsole...
来源:https://stackoverflow.com/questions/24455337/pyinstaller-on-windows-with-noconsole-simply-wont-work