[Tutor] automatically finding site-packages and python2.3 in a linux machine

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Jan 6 20:12:52 CET 2005



On Thu, 6 Jan 2005, Fred Lionetti wrote:

> I'm working on creating an installer for my program using install
> shield, and I'd like to know how one can automatically determine if
> Python 2.3 is installed on a linux machine, and where site-packages is
> located (so that I can install my own files there).  For my Windows
> version I was able to search for the python2.3 entry in the windows
> registry, but I don't know how do the equivalent from linux.  Any ideas?


Hi Fred,


Yes, there are some undocumented functions in the Distutils package that
you can use to find where 'site-packages' lives.


Let me check... ah, ok, the function that you're probably looking for is
distutils.sysconfig.get_python_lib().  For example:

###
>>> distutils.sysconfig.get_python_lib()
'/usr/lib/python2.3/site-packages'
###



def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
    """Return the directory containing the Python library (standard or
    site additions).

    If 'plat_specific' is true, return the directory containing
    platform-specific modules, i.e. any module from a non-pure-Python
    module distribution; otherwise, return the platform-shared library
    directory.  If 'standard_lib' is true, return the directory
    containing standard Python library modules; otherwise, return the
    directory for site-specific modules.

    If 'prefix' is supplied, use it instead of sys.prefix or
    sys.exec_prefix -- i.e., ignore 'plat_specific'.
    """


So you can use Python itself to introspect where the libraries should
live.  I hope this helps!



More information about the Tutor mailing list