I have created an application with pyinstaller that builds to a Windows executable, so a user can open it and from a friendly UI select a python script from a list, and then run it (all within this app), which works using subprocess.Popen
. The output of the script that they’ve selected is then displayed within the app also. The idea is that they don’t have to have any technical know-how to run these scripts, and ideally that they don’t need to have Python installed on their machine either.
It all works perfectly well on my computer, but when I run it on any other users’ computer, it runs into a litany of issues. It seems like this is because of the way my pyvenv.cfg file is setup. It has multiple references to absolute paths of my local python install such as home = C:UsersMeAppDataLocalMicrosoftWindowsAppsPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0
That is what is auto generated when I run pyinstaller, which I can of course edit and try and convert to relative paths, but that bricks it every time (typically it just acts like it’s running but actually it hangs and does nothing). My understanding after much research is that virtual environments are not meant to be portable. So is there some way for me to do this while avoiding using venv?
I currently have python bundled within my app as part of the binaries binaries=[('C:\Users\Me\Documents\Project1\project01\interface\venv\Scripts\python.exe', '.')],
It seems like there should be some way to tell pyinstaller that:
- I want to bundle python entirely within the app so that users don’t need to install python themselves and build my app themselves or whatever else
- I think I’d want to somehow not use venv, however anytime I don’t include venv, it says cannot find pyvenv.cfg
Is any of this possible? I’ve been trying variations of making this work for many days.
I have tried:
- Including the entire venv folder
- Not including any venv items including pyvenv.cfg
- Including python and all its libraries as data instead of as binary
- Having a hook that rewrites pyvenv.cfg with relative paths
- Modifying pyvenv.cfg to have local paths
- Using sys.executable to run scripts
- Directly executing script content with exec()
- Using importlib to import and execute scripts
- Modifying PyInstaller spec file to include Python interpreter
- Using PyInstaller’s sys._MEIPASS for file paths
- Executing scripts in a separate thread
- Various attempts to modify environment variables and Python paths
- Many other strategies, to no avail