Compiling mod_python for MAMP | 23 Comments
Posted in Code, Linux/Unix on 20th December 2006, 12:40 am by Stuart
Note: This post is fairly out of date and I’d recommend using mod_wsgi over mod_python. Also if you’re just looking to try out Django you can make use of the built-in development server by running python manage.py runserver
This was not the 5 minute job I had hoped it would be. I’ve been hankering to try Python and Django for a while and I though it would be a good start to get mod_python compiled for MAMP so that I could install Django on my local dev environment.
Here’s the steps I took to compile mod_python with details of the workarounds I used to fix the problems I encountered. The compilation was not for the faint of heart so if you just want to grab a universal binary of the module then you’ll find a link at the end of the article.
Steps for compilation
Download and install the latest version of Python for Mac OSX from http://www.python.org/download/
Create an alias for the newer version of python in ~/.bashrc: (Not required for the compilation but useful for running the CLI interpreter with the more recent version)
alias python='/usr/local/bin/python'
Download mod_python from here: http://httpd.apache.org/modules/python-download.cgi
cd into the unpacked source and run the following: ./configure --with-apxs=/Applications/MAMP/Library/bin/apxs --with-python=/usr/local/bin/python
This failed due to issues with the Apache version number. This seemed to relate to the build directory being missing from MAMP. To remedy this I compiled the same apache version as MAMP into a copy of the MAMP directory and then copied the build folder across to /Applications/MAMP/Library/. This allowed configure to complete.
Next I ran make.
This failed because of libtool being missing from /Applications/MAMP/Library/build/. To fix this I copied libtool into /Applications/MAMP/Library/build/ from my compiled apache. For me this was /Applications/MAMP.new/bin/apache2/build/libtool
Running make again it got a bit further but still exited with a whole heap of errors relating to includes not being available. The first of these errors was: error: httpd.h: No such file or directory.
To fix this I took a copy of the include directory in my compiled Apache (/Applications/MAMP.new/bin/apache2/include/) and put it in /Applications/MAMP/Library/
Finally make ran without hitch and after running make install I moved mod_python.so from /Applications/MAMP/bin/apache2/modules/ to the MAMP modules directory /Applications/MAMP/Library/modules/
Phew! so having got this far it was time to test if mod_python really worked. Following the instructions at http://www.modpython.org/live/current/doc-html/inst-testing.html I quickly added a directive to the httpd.conf and knocked up a quick hello world example to make sure that the compiled module did actually work.
It would be great if the MAMP developers could look to including mod_python.so in future versions but given the grief I had I can understand why this hasn’t been forthcoming. As an early Christmas present feel free to grab a copy of my universal mod_python.so (compiled for apache 2.0.59). Alternatively grab a coffee and try compiling it yourself, you know you want to!

Pingback: Django on OS X - Getting started — blog.bracewell.org
Pingback: Django on MAMP Part2 compiling mod_wsgi — blog.bracewell.org