Making a PyInstaller exe do both command-line and windowed
This is not a perfect solution, but this workaround did the job for me:
Build gui app in --noconsole --one file mode like this:
pyinstaller --noconsole --onefile hello.py
When you double click on the app from windows it will launch normally (without the console).
Now to see the output, navigate to the executable from the command line and type:
hello.exe | more
The "| more" should send the print statements to the console.
This is a problem with Windows (not PyInstaller), which requires the subsystem to be specified as either CONSOLE
or WINDOWS
at compilation-time.
The recommended solution is to split your app (eg hello
) into two distinct versions:
hellow.exe
for the GUI version (windowed) andhello.exe
for the CLI version (console)
In theory, you could also add a wrapper .exe
that switches between the two actual binaries above, depending on how it's called..