Accessing Python interpreter from a PyInstaller bundle

依然范特西╮ 提交于 2020-12-09 03:44:38

问题


I have a program (suppose it is called "PROG") that spawn Pronsole.py (3D Printing). If it is just interpreted by Python, it works good in GNU/Linux and Windows. This is the line that works:

self.pronTranspProc=reactor.spawnProcess(self.pronProtProc, pythonPath, [pythonPath, "pronsole.py"], os.environ, self.pronPathPrintrun)

When Python is the normal interpreter, "pythonPath" will be just the path to that interpreter, since it is sys.executable. But when a bundle is made with Pyinstaller so the app is frozen, sys.executable is not the interpreter, but the executable file which is generated by pyinstaller (in this example, it would be PROG.EXE instead of Python.exe). That executable has the python interpreter embedded. The problem is that if I call the executable as it if were the Python interpreter, then the program PROG opens again, which is logic, and no communication is made with the printer.

Is there any way to call the embedded Python interpreter?

Until now, the solution I have reached is adding the Python interpreter to the bundle, as a simple file. But this is redundant, since I know the interpreter is embedded. Any pythonic way of doing that?

Any help would be appreciated


回答1:


Try this:

exec(open('external_script.py').read())

The interpreter can only be referred to by a frozen script, however you can use the read function to execute the main block of your other script. Hope that helps!



来源:https://stackoverflow.com/questions/44508677/accessing-python-interpreter-from-a-pyinstaller-bundle

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