Related: After pakage a python to a exe with pyinstaller, why it can not run on a new computer?
I'm packaging a command line application with a thin GUI wrapper written in Python using pyinstaller
. I received feedback from user that it's not running. Specifically, the error message says (partially redacted):
Fatal error in launcher: Unable to create process using '"C:\Users\DannyNiu\source\repos\AutoSub\whisper-root\Scripts\python.exe" "C:\Users\DannyNiu\source\repos\AutoSub-Done\dist\main-batch\_internal\whisper-root\Scripts\whisper.exe" ...
I've got a venv in "whisper-root", and the error message seem to suggest that the executable file ("whisper.exe") is being run by the Python interpreter. The venv was in the folder "AutoSub", which I renamed to "AutoSub-Done" to induce the error.
Here's how I've been invoking the executable:
...
base = os.path.dirname(__file__)
...
whisper = base+"/whisper-root/Scripts/whisper.exe"
...
subprocess.run([whisper, ...arguments...], executable = whisper)
...
What am I supposed to do?
In a venv, only package managers such as pip
would add programs into the "Scripts" directory (where the whisper
thing resides). And when pip
does that, interpreter stubs are added to them. On most POSIX implementations, this is done by inserting the shebang (#!/interpreter/path
) as the 1st line into the text scripts; on Windows, these scripts are blessed into executable files by virtue of some compilation mechanism which embeds the absolute path of the Python interpreter program from the venv.
This has 2 implications:
This is why it breaks so terribly when moved to another computer.
What I did to work around it, is to
openai-whisper
program in an venv,site-packages
directory into Libs
in the Python instance in the packaging directory.