I am writing a script called deploy.py
.
It needs to know the location of the Python executable. Specifically the Python executable that is being used to invoke the script in the first place. The reason is that it will generate a shell script.
This is what I have been doing so far:
import sys
if __name__ == '__main__':
executable = sys.argv[1]
print executable
And call the script as python deploy.py $(which python)
. This works. Is there a better way to do this?
Of course, I am running from a virtualenv
. PYTHONPATH
in sys.environ, etc. do not work.