How do I find the full path of the currently running Python interpreter from within the currently executing Python script?
First, press Start in the lower-left corner then press Search followed by all files and folders. Type python.exe in the top text line that shows up and then press the search. A folder name will be listed where Python got installed. Hence the folder name becomes the path of Python.
Steps on WindowsOpen Search and Type Edit the System Environment Variables. Then Click on the "Environment Variables" Button in the Down Corner. There you can see all of the paths associated to where python, pip and other binaries are located that you call on command line.
The Python3 interpreter is located under /usr/bin/python3. x . Once it's done, you can open the program and start coding.
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
sys.executable
contains full path of the currently running Python interpreter.
import sys print(sys.executable)
which is now documented here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With