[mod_python] Building mod_python 3.3.1 for Python 2.5.2 on Mac OS X 10.5.2 (Leopard)

Jeffrey A. Zelt jeffreyz at broadpark.no
Sun Mar 23 17:52:27 EDT 2008

I had trouble building mod-pyhon 3.3.1 on Mac OS X 10.5.2 (Leopard),  
so I thought I would share the solution here.

I have installed Python 2.5.2 into /usr/local (to use instead of  
Leopard's default 2.5.1 distribution).  It is not that v2.5.2 provides  
so many improvements over v2.5.1; rather, Apple has shown in the past  
that they do not upgrade their version of Python between major OX X  
updates, and I would like to be able to take advantage of all future  
improvements in v2.5.x and soon v2.6.x (possibly as early as this  

I have also installed the Apache 2.2.8 web server (instead of Apples  
default Apache server, which I think is also v2.2.8).

I did not touch/modify Apple's default Python 2.5.1 or Apache 2.2.8  
installations in any way.

First, I will describe the problem and then I will show the *solution*  
that solves this problem.


If you perform a normal mod_python build, the copy of mod_python.so  
that is created by the build process has the python module import  
paths from Apple's Python 2.5.1 installation *hardwired* into it.  I  
know this is so because I looked into the mod_python.so file (even  
though this is a binary file), and I could see strings that referred  
to  Apple's Python 2.5.1 installation.

Note that this occurred even though I specified the mod_python  
configure option:


(which is the Python 2.5.2 installation I installed myself).

When I tried to connect to my Apache 2.2.8 web server with a request  
that was routed to mod_python (such as the /mpinfo testhandler), I  
received a generic 500 Server Error page in my web browser and the  
Apache error log file contained the following:

[Sat Mar 15 17:19:48 2008] [error] python_init: Python version  
mismatch, expected '2.5.2', found '2.5.1'.
[Sat Mar 15 17:19:48 2008] [error] python_init: Python executable  
found '/usr/local/bin/python'.
[Sat Mar 15 17:19:48 2008] [error] python_init: Python path being used  
[Sat Mar 15 17:19:48 2008] [notice] mod_python: Creating 32 session  
mutexes based on 256 max processes and 0 max threads.
[Sat Mar 15 17:19:48 2008] [notice] mod_python: using mutex_directory / 
[Sat Mar 15 17:19:48 2008] [notice] Digest: generating secret for  
digest authentication ...
[Sat Mar 15 17:19:48 2008] [notice] Digest: done
[Sat Mar 15 17:19:49 2008] [notice] Apache/2.2.8 (Unix) mod_ssl/2.2.8  
OpenSSL/0.9.7l DAV/2 mod_python/3.3.1 Python/2.5.1 SVN/1.4.6  
configured -- resuming normal operations

Notice that even though the Apache process found Python 2.5.2 in /usr/ 
local/bin (I was careful to set the PATH environment variable  
appropriately in my launchctl configuration file for the web server),  
the python module import paths all seem to refer to Apple's default  
Python 2.5.1 distribution (which does not have the mod_python package  
installed, of course).  Needless to say, mod_python was not useable.


1. Before building mod_python, execute:

    $ cd /System/Library/Frameworks
    $ sudo mv Python.framework XXX_Python.framework

2. After building mod_python, revert this change with:

    $ cd /System/Library/Frameworks
    $ sudo mv XXX_Python.framework Python.framework

In other words, the build process should look something like the  
following (the configure options you choose may be different that  
those I used):

    $  cd /System/Library/Frameworks
    $  sudo mv Python.framework XXX_Python.framework

    $  cd  <mod_python distribution directory>
    $  ./configure \
    > --with-apxs=/usr/local/apache2/bin/apxs \
    > --with-python=/usr/local/bin/python2.5 \
    > --with-max-locks=32
    $  make
    $  sudo make install

    $  cd /System/Library/Frameworks
    $  sudo mv XXX_Python.framework Python.framework


I am not a C programmer, but I would guess that there is a slight  
problem with the build system for mod_python on Leopard that needs to  
be fixed.  If you supply the configure option:


the build process should ignore everything to do with Apple's Python  
2.5.1 distribution, but it does not.  It seems that the "sudo mv ..."  
commands from the recipe above are enough to temporarily hide Apple's  
Python 2.5.1 distribution from the mod_python build system so that a  
mod_python.so module can be built that is solely dependendent on the  
Python 2.5.2 distribution I specified in the configure options.  Let's  
hope that the mod_python distribution is updated soon so that others  
are not bitten by this bug.

Even if my conjecture is not correct, at least you have a recipe for  
successfully installing mod_python under the conditions I outlined  


More information about the Mod_python mailing list