Sys.executable

36 views
Skip to first unread message

Sam Steinberg

unread,
Jul 25, 2019, 11:36:18 AM7/25/19
to PyInstaller
I have seen there is Pyinstaller documentation covering why sys.executable and sys.argv[0] do not work after freezing and bundling into an application.

Due to this I understand why my application works by using the path to the python executable in, say, an IDE but not after bundling where sys.executable will now be the frozen .exe.

The documentation, however, does not give an alternative. For my specific issue I am trying to run a subprocess and need to use the Python interpreter (sys.executable elsewhere).

Has anybody come across this issue and know a solution?

This is my first post here, so if I need to post more info please let me know :)

Spencer Brown

unread,
Jul 26, 2019, 3:48:24 AM7/26/19
to PyInstaller
When you freeze an application with PyInstaller, it doesn't have all of the interpreter - just the modules you use. What you should do is alter your main script to take command line arguments, and then pass an argument that makes it do whatever you would have called the interpreter to execute. In other words call sys.executable to produce a clone of your application, which runs whatever other command instead of your normal application. If you're wanting to run any Python commands, that kinda defeats the purpose of freezing. You might as well just install the whole interpreter and provide your code as a script or something.

For running your command line args, you might want to look at the runpy, and code modules - these implement -m execution and a REPL respectively.

Sam Steinberg

unread,
Jul 26, 2019, 6:48:19 AM7/26/19
to PyInstaller
I appreciate the response Spencer.

I understand your point that the whole interpreter is not bundled. However, is there still no way to run a separate script without importing a module like runpy?

For example (I am using PyQt5) if I call a script called submodule.py from main.py like so: QProcess.start(path_to_python.exe, ["submodule1", ...args...]) is this no longer possible?

So this submodule would simply take command line arguments given to it by the main.py, but as of now without the sys.executable, etc. when I turn main.py into an .exe it obviously fails.
Reply all
Reply to author
Forward
0 new messages