Website of Daniel A. Mayer

Compiling Mod_wsgi for a Custom Python Build

Recently, I have been working on deploying a pyramid (former pylons) application on a Debian 5 (Lenny) server using mod_wsgi and Python 2.7. Since Lenny only comes with Python 2.5 and third-party Python packages are basically non-existent due to dependency problems, newer Python versions need to be compiled manually.

Compiling Python

A detailed tutorial is available at projectdaenney.org but for our purposes a very basic configuration suffices. Download the Python 2.6 or 2.7 sources, extract them  and then run:

1
2
3
./configure --enable-shared --with-threads
make
make install

Note that Python is configured to build a shared library (--enable-shared) which is required to avoid several problems detailed in the mod_wsgi manual

Compiling mod_wsgi

Next we can download the mod_wsgi sources, extract them and compile using the following commands:

1
2
3
./configure  --with-python=/usr/local/bin/python2.7
make
make install

Note that the newly compiled Python executable is explicitly passed via --with-python=/usr/local/bin/python2.7.

Configuring mod_wsgi

From here you can follow the instructions in the excellent mod_wsgi documentation to deploy your application.

Caveats

If Python is unable to find the runtime library you will receive the following error message when configuring mod_wsgi: /usr/local/bin/python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

As pointed out in the DotMatrix Blog this problem can be solved by creating the following two symlinks:

1
2
ln -s /usr/local/lib/libpython2.7.so.1.0 /usr/lib/
ln -s /usr/local/lib/libpython2.7.so /usr/

If you are running a 64-bit operating system the former needs to be changed to /usr/lib64/ instead of /usr/lib

References:

Comments