How do I launch another Python process with subprocess from within a PyInstaller executable?
That is, I have a Python script that I compile with PyInstaller to an executable. Inside this Python script, at some point I need to launch another Python process with subprocess (I have a good reason for using subprocess instead of multiprocessing here, namely because it seems to be the only way to open the new process in a new console window, with creationflags=CREATE_NEW_CONSOLE_WINDOW on Windows):
subprocess.run([sys.executable, "-m", "some.module", ...])
However this approach doesn't work, because when the PyInstaller-compliled executable runs, sys.executable is no longer a path to the Python interpreter, but rather it's the path to the executable itself. I don't want to use just "python" either because I want to make sure it's using the exact same Python interpreter that is used to run the main program.
Another reason for using subprocess is that if I find out a way to start a Python process by explicitly calling the interpreter as above (with the argument list [sys.executable, ...]), I will be able to use the async version of subprocesses, asyncio.subprocess, which has an API very similar to subprocess. There doesn't seem to be an asyncio equivalent of multiprocessing.