[Python-Dev] Finding the python library binaries (and docs)

David Abrahams dave at boost-consulting.com
Tue Mar 6 20:20:56 CET 2007

I'm trying to find the Python library binaries associated with a given
python executable. 

If I look at the help for sys.prefix and sys.exec_prefix

   import sys; help(sys)

I see:

    prefix -- prefix used to find the Python library
    exec_prefix -- prefix used to find the machine-specific Python library

This text is somewhat ambiguous, but from the fact that exec_prefix
refers to the "machine-specific" Python library I'm led to guess that
prefix's "the Python library" refers to the *.py* files that form most
of the Python standard library, and "the machine-specific Python
library" perhaps refers to the library binaries such as libpython25.a.

However, neither of those interpretations seems to correspond to
reality.  My guess is that these constants correspond to the --prefix
and --exec_prefix options to the configure script invocation that was
used to build Python.

What I'm really looking for, I think, is the directory corresponding
to the --libdir option to configure, but I don't see that in sys.  

If I look at "configure --help," it claims the default libdir is
EPREFIX/lib, so I suppose I could look in sys.exec_prefix+'/lib', but
when I look at real installations I find only the shared libraries in
that location.  For the static libraries, I have to look in
EPREFIX/lib/python$(version)/config/, and in fact there is a symlink
there to the shared libs.


  1. I think the documentation for sys and configure both need some

  2. I'd like to know if there's an officially correct procedure for
     finding the library binaries associated with a Python executable.

Thanks in advance,

Dave Abrahams
Boost Consulting

More information about the Python-Dev mailing list