9

I am using Debian (which comes with Python-2.7.3), trying to compile Python-2.7.6 from source for use with mod_wsgi alongside Apache.

Apparently you must use --enable-shared when compiling for mod_wsgi usage, according to numerous answers.

Following these steps:

./configure --enable-shared --prefix=/usr/local/bin/python-2.7.6
make
make install

And then checking the interactive shell @

/usr/local/bin/python-2.7.6/bin/python

I am greeted with "Python 2.7.3 (default, Jan 2 2013, 14:09:21)" etc

Why is it resulting in Python 2.7.3?

I tried ldd against the executable and this is the result:

linux-vdso.so.1 =>  (0x00007fff271ff000)
libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0x00007f1545638000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f154541c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1545217000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f1545014000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1544d92000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1544a06000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f15447ef000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f15445d9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1545b40000)

How do I stop it from using the system library and instead use the locally compiled version?

I know that it is a lot easier for me to just revert to using the system installed Python version, and that the real-world difference is zero. But this behaviour seems strange.

Chris Berry
  • 568
  • 7
  • 11

1 Answers1

17

When you do the make of Python, run it as:

LD_RUN_PATH=/usr/local/lib make

Setting the environment variable LD_RUN_PATH forces 'python' executable generated to look in /usr/local/lib before /usr/lib for Python shared library.

This is mentioned in the mod_wsgi documentation.

Before doing this again, make sure you do a 'make distclean' and rerun configure to make sure you haven't got old build products around.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • 1
    What I ended up having to do was: compile python once with --enable-shared, make install into the dir, make distclean it, set LD_RUN_PATH to the newly compiled lib folder, make again with --enable-shared, remove the previously compiled version, make install. And once more recompile mod_wsgi against the new python. Thanks very much for the pointer in the right direction. – Chris Berry Mar 04 '14 at 14:34
  • 1
    Random note: you can actually add an RPATH post-compilation, using a beautifully simple program called patchelf. This was news to me recently and has saved me from recompiling something just because I forgot to set the RPATH/RUN_PATH. Highly recommended: https://nixos.org/patchelf.html – CptSupermrkt May 07 '15 at 16:49
  • Good to know about patchelf. I used to use a program like that on Solaris back in the early 90s. Didn't know such a thing existed for Linux. – Graham Dumpleton May 08 '15 at 04:15