Obtain the Path of Current Python Interpreter by sys.executable

Jul. 08, 2024

As in the official documentation1, by executing sys.executable function of Python sys package, we can get:

A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None.

Take my case.

1
2
import sys
sys.executable
1
'G:\\Spyder\\Python311\\python.exe'


References