accessing python interpreter from a pyinstaller bundle #2

我与影子孤独终老i 提交于 2021-01-28 09:41:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!