10

I wish to compile Python 2.7.3 from source. The OS is OpenSUSE 11.4 x86_64, which already provides Python 2.7. I'd like to use 2.7.3 for the latest security patches, but it's a shared system so I can't tinker with the system Python interpreter.

I compile using ./configure --prefix=/opt/python --enable-shared. No configure errors, so I make. Again no errors. I do a make install (I don't think I need make altinstall, since this installation prefix in /opt/python isn't in use yet).

When I try to run the new binary /opt/python/bin/python, Python announces its version as 2.7, not 2.7.3. The only way I've found to correct this is to move the system's /usr/lib64/libpython2.7.so.1.0, and symlink it to /opt/python/lib/python/libpython2.7.so.1.0. This works and Python announces it is 2.7.3, but this breaks the system Python.

Is there anyway I can get the two to coexist, e.g. by getting the /opt/python to use its own libpython? Other than supplying LD_LIBRARY_PATH at runtime. Is there a compile time solution? Thanks.

2
  • Do you require --enable-shared? I've built a custom Python zillion times (without --enable-shared) on various distributions and the only thing required to use this Python then is to modify PATH. Commented Sep 23, 2012 at 14:50
  • 2
    Note that if you build Python without --enable-shared, you get a huge executable that contains the entire shared library. The shared library is needed for embedding, which is why Linux distributions build with --enable-shared. Commented Sep 23, 2012 at 15:30

1 Answer 1

25

To avoid having to specify the runtime library path using LD_LIBRARY_PATH each time Python is started, you can specify it at build time using the -rpath linker option:

./configure --enable-shared --prefix=/opt/python \
            LDFLAGS=-Wl,-rpath=/opt/python/lib
Sign up to request clarification or add additional context in comments.

1 Comment

This works great, but in case you run into issues with existing LDFLAGS, you can alternatively set the LD_RUN_PATH environment variable to the absolute library directory path at compile time (see blog.dscpl.com.au/2015/06/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.