e.g., how can I find out that the executable has been installed in "/usr/bin/python" and the library files in "/usr/lib/python2.6"?
+1
A:
You want the sys
module:
>>> print sys.executable /usr/bin/python >>> print sys.path ['', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']
jemfinch
2010-04-11 06:03:15
not quite... I'm looking for where the installer installed the system libraries, not the system libraries which are on the path.
Mark Harrison
2010-04-11 06:59:44
+1
A:
distutils.sysconfig is the module that "provides access to Python’s low-level configuration information". The get_python_lib function, in particular, gives "the directory for either the general or platform-dependent library installation", depending on its arguments.
However, sys.executable
is not exposed by said sysconfig
module -- it's only in the sys
module.
Alex Martelli
2010-04-11 06:10:00
Thanks Alex! It looks like get_python_lib(1,1) is just what I need. Calling with the default parms returns the site_packages directory.
Mark Harrison
2010-04-11 06:50:45