3

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?

Jerry YY Rain
  • 4,134
  • 7
  • 35
  • 52
GuyC
  • 999
  • 1
  • 8
  • 15

2 Answers2

8

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...

TheClockTwister
  • 819
  • 8
  • 21
  • 3
    Leon, your code helped me solve my problem. [My GUI Issue](https://stackoverflow.com/q/61326495/8271606). Thank you greatly! – Hellyeah Apr 21 '20 at 12:42
5

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:

  1. The multiprocessing module needs to set an environment variable when it spawns worker processes.
  2. The subprocess module needs to explicitly handle stdin, stdout, and stderr, because the standard file handles aren't set for subprocesses to inherit.
  3. The subprocess creates a console window, unless you tell it not to.
Community
  • 1
  • 1
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
  • 1
    I found point 2 worked - explicitly handling stdin, stdout and stderr. We only handled stdout and stderr in our subprocess, but once we handled stdin it worked perfectly. – Lauren Apr 10 '19 at 14:16
  • A few years later, I found this and #2 solved my issue too. Thanks! – SLAVA Jan 27 '20 at 20:39