Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 273
neurino Avatar asked Mar 01 '11 13:03

neurino


1 Answers

The path is available in sys.executable.

like image 131
Sven Marnach Avatar answered Nov 19 '22 07:11

Sven Marnach