[Distutils] Looking for portable what to determine directory where extensions are installed?

Tom Epperly tepperly at llnl.gov
Wed Nov 11 18:46:25 CET 2009

[I am resending this because nobody responded to my first inquiry. I am 
hoping it just got overlooked in the discussion about CPAN because I am 
looking for the right solution for a bug in my tool that links Python to 
other languages.]

I work on a language interoperability tool, Babel
https://computation.llnl.gov/casc/components/components.html; and I need
a portable way to determine the directory where Python extension modules
are installed by distutils (i.e., lib or lib64) to resolve this issue:

For example, I will invoke "python setup.py install
--prefix=/home/foo/_inst --exec-prefix=/home/foo/_inst", and it usually
installs the extensions in either
/home/foo/_inst/lib/python2.5/site-packages or
/home/foo/_inst/lib64/python2.5/site-packages. Initially, I did the
following to determine where the extensions actually got installed:

# assume exec_prefix=/home/foo/_inst
# assume python_version=`python -c 'import sys; print sys.version' | sed

This worked fine until I started running on 64-bit Python machines where
the correct result was


The first 64-bit machine I was using seemed to have this patch:
http://bugs.python.org/file14726/Python-2.6.2-multilib.patch, so I
amended my script to the following:

pylib=`$PYTHON -c "import sys; print sys.__dict__.get('lib','lib')"`

However, this approach doesn't work with Fedora Core 12 prerelease or
some other 64-bit Linux distributions. They don't define "sys.lib".

I thought distutils.sysconfig.get_python_lib() might be helpful, but it
returns "/usr/lib/python2.6/site-packages" even on the system where
"/usr/lib64/python2.6/site-packages" is the right answer.

Is there a canonical, Pythonic way to determine whether an installation
of Python uses "lib" or "lib64"?  Or is there a way to determine the
full path of where distutils will install extensions relative to the
specified exec prefix?


Tom Epperly

More information about the Distutils-SIG mailing list