How to programmatically get python.exe location?

Basically, I want to get a python interpreter handle so that I can pass the script file for execution (from an external application).

+75
python
Apr 14 '09 at 23:29
source share
3 answers

Does it work on Linux, maybe on Windows too?

>>> import sys >>> print sys.executable /usr/bin/python 
+129
Apr 14 '09 at 23:46
source share
— -

sys.executable is not reliable when working in the python embedded environment. My suggestions are to get him out of

 import os os.__file__ 
+28
Nov 18 '11 at 18:14
source share

I think it depends on how you installed python. Please note that you can have several python installations that I do on my machine. However, if you install python version 2.2 or higher via msi, I believe that it creates such a registry key:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Application Paths \ Python.exe

which gives this value on my machine:

C: \ Python25 \ python.exe

You just read the registry key to get the location.

However, you can install python using an xcopy-like model, which you can have in any place, and you just need to know where it is installed.

+4
Apr 14 '09 at 23:39
source share



All Articles