I have a tkinter GUI with a text box and run button. Pressing the run button turns it to yellow and starts a subroutine that prints a few numbers. Text output from the subroutine is redirected to the GUI text box. However, after creating a standalone executable file with pyinstaller, it no longer works. Pressing the run button doesn't seem to start the subprocess. It does turn yellow, but no text appears in the text box and it seems to start another instance of the main program - a second GUI appears after about 10 seconds which is how long it takes for the initial GUI to appear. The run button stays yellow on the initial GUI.
I've seen a bit online about other people having issues with subprocesses not running after pyinstaller, but most of the solutions seem to be to make sure stdout, stdin are set to subprocess.PIPE which I have, so I'm at a bit of a loss what to try next.
When running the resulting executable from Anaconda prompt, I also get no error messages or anything useful to help debug.
I'm creating my standalone with this:
pyinstaller --onefile --add-data "testsubprocess.py;." simpleGUI.pyMy subprocess file, testsubprocess.py is:
My main GUI file, simpleGUI.py, is:
A couple of things occur to me on looking at your code:
When you code: self.process = subprocess.Popen([sys.executable, "-u", "testsubprocess.py"], shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT) is executed directly as python simpleGUI.py then sys.executable will be /path/to/python.exe but when you execute your simpleGUI.exe then it will be simpleGUI.exe this is why you get a new instance!
Hope that helps!
Steve
--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
pyinstaller...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyinstaller/127a328b-e2c9-4d08-8a71-f574b0c18420n%40googlegroups.com.
subprocess.Popen([sys.executable, “-u”, “testsubprocess.py”],
A frozen application does not ship a Python interpreter. Instead sys.executable points to your EXE file which is equivalent to python testsubprocess.py so what you’re effectively running is subprocess.Popen(["python", "testsubprocess.py", "-u", "testsubprocess.py"], which will result in an infinite loop of subprocesses with every process invoking another child process. As Steve says, use the multiprocessing module and make sure you use the freeze_support() function.
And for the reference, the issue with having to assign all 3 stdin, stdout, stderr is only applicable to --windowed mode and simply results in an exception of you don’t do it.
Hi Matthew,
That will work on your machine at least as long as you don't change where python is installed but not on the machine of anybody else who doesn't have python installed in exactly the same place - since you are using pyinstaller I would guess that this is not what you would want.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/77c2276a-8850-406e-bc7d-75dfdbf75ed6n%40googlegroups.com.