开发者

get path of python binary that's executing the script [duplicate]

开发者 https://www.devze.com 2023-02-13 22:57 出处:网络
This question alre开发者_JAVA百科ady has answers here: How to get the python.exe location programmatically? [duplicate]
This question alre开发者_JAVA百科ady has answers here: How to get the python.exe location programmatically? [duplicate] (3 answers) Closed 6 years ago.

I have a Pylons controller (irrelevant but explains why I have this need) say starter.py that starts another process using:

retcode = subprocess.call(('python','/path/to/myScript.py'))

now since the app runs in a virtual env python is not the right binary to call since it has no access to site-packages installed in my virtual env.

It should be instead:

retcode = subprocess.call(('path/to/virtual/env/bin/python','/path/to/myScript.py'))

and path/to/virtual/env/bin/python is the same that is running starter.py.

Any chance to not set this path (say, in a .ini file) and retrieve it?


The path is available in sys.executable.

0

精彩评论

暂无评论...
验证码 换一张
取 消