get path of python binary that's executing the script

Question:

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?

Asked By: neurino

||

Answers:

The path is available in sys.executable.

Answered By: Sven Marnach
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.