How do I know which source I'm running Python?

3

I'd like to know how do I know which source I'm running the Python from.

For example, if I installed Python 3.5 on my machine and created a Virtualenv, how could I know from Python itself the source of execution of that binary?

For example, if I run Python , I know the full path of the executable, such as /usr/bin/python , for example.

In the specific case, I do not want anything referring to Virtual Env, but to know by Python the source path of the binary.

    
asked by anonymous 23.07.2018 / 19:47

1 answer

5

Use sys.executable . So:

import sys
print(sys.executable)

# Output '/usr/bin/python'

According to the sys documentation Python:

  

A string that provides the absolute path of the executable binary to the Python interpreter on systems where this makes sense. If Python can not retrieve the actual path to its executable, sys.executable will return an empty string or None .

    
23.07.2018 / 20:46