Find full path of the Python interpreter?


Question

How do I find the full path of the currently running Python interpreter from within the currently executing Python script?

1
333
10/16/2016 8:58:22 AM

Accepted Answer

sys.executable contains full path of the currently running Python interpreter.

import sys

print(sys.executable)

which is now documented here

514
11/9/2015 9:16:39 PM

Just noting a different way of questionable usefulness, using os.environ:

import os
python_executable_path = os.environ['_']

e.g.

$ python -c "import os; print(os.environ['_'])"
/usr/bin/python

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon