I've compiled python 2.7.8 with:

mkdir -p /usr/local/python2p7/lib
./configure --prefix=/usr/local/python2p7 --with-threads --enable-shared LDFLAGS="-Wl,-rpath /usr/local/python2p7/lib"
make install altinstall

I'm using the LDFLAGS so this install doesn't conflict with CentOS 7 built in python 2.7.5.

I compile modwsgi 4.2.6:

./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python2p7/bin/python LDFLAGS="-L/usr/local/python2p7/lib"
 make install

If I run:

ldd /usr/local/apache/modules/mod_wsgi.so

I get

libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x00007f648d9a0000)

How do I get mod wsgi to use /usr/local/python2p7/lib/libpython2.7.so.1.0?


With the help of Graham Dumpleton:

To compile modwsgi:

export LD_RUN_PATH=/usr/local/python2p7/lib
./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python2p7/bin/python
make install

In apache config set

WSGIPythonHome /usr/local/python2p7

I initial set it to "/usr/local/python2p7/bin" and got the "ImportError: No module named site" error.

  • You have a really good reason for compiling your own Python, right? – Michael Hampton Jul 21 '14 at 2:54
  • Yes. I use the latest python. This wasn't an issue with CentOS 6 which uses < python 2.7. – brian Jul 21 '14 at 3:00
  • OK, so you don't actually have a good reason? – Michael Hampton Jul 21 '14 at 11:55

This is covered in the mod_wsgi documentation. See:

You will need to set LD_RUN_PATH environment variable to appropriate library directory when compiling mod_wsgi to ensure it uses the correct Python shared library.

Also read:

in case at run time it still picks up wrong run time files. In that case you need to also set WSGIPythonHome.

As far as compiling from source code, the other reason is that CentOS still ships an old mod_wsgi.

You might even consider using the pip installable mod_wsgi in place of doing what you are doing now. See:

  • setting the env var LD_RUN_PATH fixed the problem. I thought setting the configure flag LDFLAGS would do the same thing. – brian Jul 22 '14 at 18:13
  • LDFLAGS is setting options to be used at compile time linking to find it and know it exists. LD_RUN_PATH is embedding directories to be searched at run time for the shared library. – Graham Dumpleton Jul 23 '14 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.