How to get the python.exe location programmatically? [duplicate]

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


Solution 1:

This works in Linux & Windows:

Python 3.x

>>> import sys
>>> print(sys.executable)
C:\path\to\python.exe

Python 2.x

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

Solution 2:

sys.executable is not reliable if working in an embedded python environment. My suggestions is to deduce it from

import os
os.__file__