tags:

views:

93

answers:

3

Possible Duplicate:
Getting python.exe path at run time

I have a python app that launches other apps with explicit calls to C:\python25\python.exe, but this doesn't work if the user has 2.6 installed or if they have it installed to another location. There is a %PYTHON% variable for the exe, but this is only available to the user who installed Python (other users don't have this envvar set).

Is there another way to look up this location?

+8  A: 
import sys
print sys.executable
nosklo
Is there anything sys can't do? Thanks!
directedition
+4  A: 
>>> import sys
>>> sys.executable
'C:\\Program Files\\Python31\\pythonw.exe'
SilentGhost
I beat you by 17 secs :P
nosklo
it took me time to open IDLE ;)
SilentGhost
17 seconds cause five people to upvote nosklo's answer and not upvote this one. (shakes head) +1 to both
Graeme Perrow
I don't think it's correct Graeme, all votes were cast after recursive's answer.
SilentGhost
My point was that your answer and nosklo's answer were posted 17 seconds apart, and say almost *exactly* the same (correct) thing, yet his answer has 5 more (at the time - 4 more now) upvotes than this one.
Graeme Perrow
+1  A: 

Consider using execfile. This executes the script you want using the same python instance that's already running.

recursive
Not downvoting. But I consider this bad advice, what's the advantage of using execfile in this case (above a regular 'import')?
ChristopheD
It connotes executing the file rather than importing a library. What is the disadvantage?
recursive
My software launches many instances of python, being to use execfile would help restore sanity to my list of running processes.
directedition
Can command line arguements be passed?
directedition