问题
I'm trying to execute a python script which is included in datas, and bundled into a pyinstaller executable (on a mac). I need to pass parameters to this script, so I can't just exec(open(read()). Outside of pyinstaller, sys.executable is the python interpreter, so calling the python script works fine. In pyinstaller, sys.executable is the 'main' py script, so it just opens up my app again instead of calling the new script. How can I call my additional python script inside my app? This is what I'm trying to acheive, which does not work with a bundled pyinstaller app:
subprocess.call([sys.executable, os.path.join(wd,"tests","errorMessage.py"), vArgument])
回答1:
This is how I got it to work, which is kinda janky imo. It doesn't call the python interpreter as I originally wanted, but executes the py script including arguments:
# set the arguments beforehand
sys.argv = [os.path.join(wd,"tests","errorMessage.py"), vArguments]
# execute the script, but also bring in globals so imported modules are there
exec(open(os.path.join(wd,"tests","errorMessage.py")).read(), globals())
Pyinstaller seems to work after this whole deal.. omg...
来源:https://stackoverflow.com/questions/60253999/accessing-python-interpreter-from-a-pyinstaller-bundle-2