SubProcessWorker command hardcoded path in relation to PyInstaller setup

Hi!

I’d like to bundle my PySide6 application and all its dependencies into a package using PyInstaller.

I have a SubProcessWorker in which I have a command:
command=“absolute_path_to_venv\python.exe script.py”

I suspect that I should replace my absolute hardcoded path to python with more flexible solution, am I right (different users have different paths)? If so, what is the proper solution in this case?

Hi @Mikolaj

Can you tell me, you use subprocess module to run script.py inside other python script/appliaction?

I guess for some reason, you can’t import this script.py and do what you need to do?

Hi @Michal_Plichta ,

Thank you for your reply.

Let me rephrase my question in more detailed way.

I’m using “qrunnable_process_parser.py” script from @martin 's “Create GUI Applications with Python & Qt6 Pyside6 Edition”.

There is part:

def start(self):
# Create a runner
self.runner = SubProcessWorker(
command="python dummy_script.py",
parser=simple_percent_parser,
)

Since my python sits in the virtual environment I changed the code to:
command="my_hardcoded_absolute_path_to_venv/python dummy_script.py",
so it could work.

Now I would like to bundle this application into a package using PyInstaller.
I assume that after bundling, my application won’t work on any users machine, because this is my hardcoded path to python exe.

If my assumption is right, what should I replace my hardcoded path with?

@Mikolaj
If you really need run: python dummy_script.py from your application, I see 3 soulutions:

  1. Try accessing python interpreter from a pyinstaller bundle but I didn’t try it and using exec() is not recommended.
  2. allow user to pass path to python interpreter, but it kill idea of pyinstaller itself, so user do not have to install python
  3. make pyinstaller bundle from python dummy_script.py. with:
    pyinstaller.exe --no-console --onefile dummy_script.py and then use pyinstaller again with your main appliaction, but remember include dummy_script.exe add data/resource in pyinstaller spec file.