Locate python home

Mike C. Fletcher mcfletch at rogers.com
Wed Feb 25 04:19:14 EST 2004


Thomas Aanensen wrote:

>Python could be located at different paths on computers (e.g. c:\python).
>How can I find this path?
>  
>
PythonWin 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] 
on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - 
see 'Help/About PythonWin' for further copyright information.
 >>> import sys
 >>> sys.executable
'C:\\bin\\lang\\py23\\Lib\\site-packages\\Pythonwin\\pythonwin.exe'
 >>> sys.prefix
'C:\\bin\\lang\\py23'

V:\cinemon>python
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.executable
'c:\\bin\\lang\\py23\\python.exe'
 >>> sys.prefix
'C:\\bin\\lang\\py23'

Python 2.3.3 (#1, Jan 29 2004, 21:46:45)
[GCC 3.2.2 [FreeBSD] 20030205 (release)] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.executable
'/usr/local/bin/python'
 >>> sys.prefix
'/usr/local'

That is, sys.executable will give you the name of the executable which 
is currently running.  Py2exe, PythonWin, etceteras can all wind up 
making it say things you might not consider to be Python (they're not 
python.exe), but it's the best approximation to "where's Python" for 
most needs of the information.  sys.prefix/sys.exec_prefix is going to 
need platform-specific munging to make any sort of sense for most values 
of "where's Python".  See documentation on the sys module for more details.

HTH,
Mike

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/






More information about the Python-list mailing list