Python Sys – Get location of Python interpreter

In this post we will be creating a script that will retrieve and return the location of the current Python interpreter. To do this we will use the Sys module which gives us access to variables used or maintained by the interpreter.

See the snippet of code below which will return the location of the Python interpreter.

import sys

print(sys.executable)

An example of what the above will return can be seen below.

C:\Users\\AppData\Local\Programs\Python\Python39\pythonw.exe
>>> 

Leave a Reply