sys.executable
The full path of the Python interpreter file that is running the current program.
In more detail
Printing it answers which Python am I beyond doubt, which matters when several are installed or a virtual environment is involved. Running sys.executable -m pip installs packages into exactly that interpreter.
Example
import sys
print(sys.executable)Related terms
- sys module — The standard library module through which a program asks the running interpreter about itself.
- which command — A shell command that shows which program a command name will run, by searching PATH the same way the shell does.
- PATH — An environment variable holding a list of folders the shell searches, in order, to find the program for a command you type.
Taught in
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- First Run, And Fixing A Broken Install — Hands-on Python: Complete Video Course & Book