Basically I want to get a handle of the python interpreter so I can pass a script file to execute (from an external application).
+3
A:
I think it depends on how you installed python. Note that you can have multiple installs of python, I do on my machine. However, if you install via an msi of a version of python 2.2 or above, I believe it creates a registry key like so:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App 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 via an xcopy like model that you can have in an arbitrary place, and you just have to know where it is installed.
Justin
2009-04-14 23:39:52
If it is in App Paths you don't even need to know the location do you? ;)
Gleb
2009-04-14 23:45:06
+8
A:
This works in Linux, perhaps in Windows too?
>>> import sys
>>> print sys.executable
/usr/bin/python
mhawke
2009-04-14 23:46:57
Yep - >>> import sys | >>> print sys.executable | C:\Python25\pythonw.exe
Smashery
2009-04-14 23:50:01
I think in a py2exe compiled app, it would point to the executable for the app, and not the python.exe. Someone would have to confirm though.
FogleBird
2009-04-14 23:53:48
That only makes sense if you are already running the Python interpreter. I think he's trying to find the location from outside of Python itself.
John Montgomery
2009-04-15 10:38:06