How to get the python.exe location programmatically?

StackOverflow

Basically I want to get a handle of the python interpreter so I can pass a script file to execute (from an external application).

Answer rating: 315

This works in Linux & Windows:

Python 3.x

>>> import sys
>>> print(sys.executable)
C:path	opython.exe

Python 2.x

>>> import sys
>>> print sys.executable
/usr/bin/python




Get Solution for free from DataCamp guru