views:

568

answers:

4

I want to know where is the python's installation path. For example:

C:\Python25

But however, I have no idea how to do. How can I get the installation path of python?

Thanks.

+3  A: 

In the sys package, you can find a lot of useful information about your installation:

import sys
print sys.executable
print sys.exec_prefix

I'm not sure what this will give on your Windows system, but on my Mac executable points to the Python binary and exec_prefix to the installation root.

You could also try this for inspecting your sys module:

import sys
for k,v in sys.__dict__.items():
    if not callable(v):
        print "%20s: %s" % (k,repr(v))
Guðmundur H
+1  A: 

On my windows installation, I get these results:

>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'
>>> sys.platform
'win32'
>>>

(You can also look in sys.path for reasonable locations.)

gimel
+2  A: 
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
elo80ka
+4  A: 

If you need to know the installed path under Windows without starting the python interpreter, have a look in the Windows registry.

Each python installed Python version will have a registry key in either:

  • HKLM\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
  • HKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
codeape