Linux/Win32 func. to get Python instdir (not exedir) + site-packages => extensions mgmt

pythonewbie eproust at
Sun Jan 20 23:49:21 CET 2008

On 20 jan, 23:19, "Martin v. Löwis" <mar... at> wrote:
> > But for different reasons I also want to get the absolute path of
> > Python install directory (not only the executable under Linux) and
> > site-packages directory.
> The Python install directory is available as sys.prefix. The
> site-packages directory is
> sys.prefix+"lib/python"+x.y+"/site-packages (where x.y is from
> sys.version_info).
> HTH,
> Martin

>>> import distutils.sysconfig
>>> distutils.sysconfig.get_python_lib()

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

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

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

More information about the Python-list mailing list