I want to run a Python script from a Python script with subprocess
, and I wish to do it using the same interpreter for each of them.
I'm using virtualenv, so I'd like to do something like:
subprocess.Popen('%s script.py' % python_bin)
How do I get python_bin
?
It should be /usr/bin/python
outside a virtualenv, and /path/to/env/bin/python
in a virtualenv.
The name of the interpreter is stored in the variable sys.executable