Looking for portable what to determine directory where extensionsare installed?

Discussion in 'Python' started by Tom Epperly, Nov 5, 2009.

  1. Tom Epperly

    Tom Epperly Guest

    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:
    https://www.cca-forum.org/bugs/babel/issue670

    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 '1s/^\(...\).*/\1/g;1q'`
    RUNTIME_PYTHON="$exec_prefix/lib/python$python_verbose/site-packages"

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

    RUNTIME_PYTHON="$exec_prefix/lib64/python$python_verbose/site-packages"

    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')"`
    RUNTIME_PYTHON="$exec_prefix/$pylib/python$python_version/site-packages"

    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?

    Regards,

    Tom Epperly
     
    Tom Epperly, Nov 5, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eli Bendersky
    Replies:
    1
    Views:
    1,211
    Mike Treseler
    Mar 1, 2006
  2. Learner
    Replies:
    4
    Views:
    2,131
    Learner
    Jan 27, 2006
  3. Replies:
    7
    Views:
    954
  4. Replies:
    3
    Views:
    490
    Jason
    Apr 28, 2008
  5. gk
    Replies:
    3
    Views:
    412
    RedGrittyBrick
    May 18, 2010
Loading...

Share This Page