Compiling mod_python for MAMP | Comments (18)
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!

Welcome to the club.
Thanks for the write up…and the pre-compiled universal mod_python.so. I was interested in Python and Django a while back, but have since had to put it on the back burner. I’m already so deeply entrenched in PHP (CakePHP) and C#(ASP.NET) that it’s hard to find time for new stuff. Heck, I still get jobs coding ASP 3.0 sites for people! I also looked at RoR around the same time, and decided to put it on the back burner as well. I hope I have time to come back to them sometime before too long…they both seem like useful tools.
What about XAMPP?
What about it?
You can download binaries for Win32 from here http://www.apache.org/dist/httpd/modpython/win/
Merry Christmas!
I have a quick question. Am I supposed to just copy the copy your compiled mod_python.so to the /Applications/MAMP/Library/modules, add the directive in httpd.conf and restart the server? Will that have it ready to go? Any help would be great! I have wanted to mess around with Django and Python but don’t feel like getting into complicated installation procedures.
Thanks again!
@Foad: That should do it. If you have any probs then let me know through the contact form. I also managed to get the mysqldb package compiled and installed too so if you need that let me know.
do you have a more updated mod_python to work with latest mac python ??
Latest MAMP with Apache 2.0.59 seems to work with mod_python out of box. Just ./configure as above then make & sudo make install.
I am in the same boat as John Chapnick, Need a mod_python to work with Mac Python 2.5.1. I have tried the instructions to create and Apache seems to think mine is “garbled”.
Thanks so much for the download link! Your a live saver!
Thanks for the info, Stuart - this saved my sanity trying to get Django running under my MAMP Pro the
other day.
Having had a chance to go through the process again, I realised that you can download MAMP including all
the build libraries from the usual place - just pick the appropriate "Full" version under
‘Additional Downloads’.
This avoids the need for making a MAMP.new, or recompiling Apache, though your instructions will still be
useful for those who don’t want to reinstall MAMP because they have many sites already.
Hope this helps! I am in the process of writing up my own process, and will comment again when it’s
online.
Greg.
Stuart, can you say a bit more about using compiling/installing mysqldb? I’m having trouble getting my python scripts to connect to MySQL.
Thanks for the great post!
On osx leopard python is installed by default and installing it like you suggested will mess up the right paths. You could modify your article to say so.
If you allready messed up your paths then you can change your paths or uninstall installed package by removing it from:
/Applications/yourpythondir
/Library/frameworks/pythonframework
/Developer/documentation/python/link to yourdocs
and clearing a path from your ~/.basc_profile
then you can use your compiled mod_python with mamp with no problems. default installation is in /usr/bin/
leopard also comes with svn preloaded if you need to use trac then all you need to do is write to terminal ‘easy_install Trac’ and it downloads all dependencies aso
Thanks to Stuart for his initial guidance and thanks to the commenters for adding additional info!
With your collective help I got mod_python running on my MAMP installation in no time…
regarding comments 5 and 6 by @FOAD and Stuart, which file do I need to edit to and what do I need to put there to to get mod_python recognized by MAMP? I’m running MAMP 5.2.3 under Leopard on 10.5.2 on a Quad G5.
Hey Stuart,
Thanks for this, it helped me get up and running. As Greg Turner notes, above, downloading the full version of the latest MAMP meant that I didn’t have to compile Apache myself.
[...] MAMP to serve our Django apps we need to install mod_python. Stuart Colville’s experiences compiling mod_python for mamp didn’t fill me with confidence but I’d thought I’d go ahead and give it a stab so [...]
[...] and unpacked using tar xvzf mod_wsgi-2.0.tar.gz Cribbing Stuart Colville’s post on compiling mod_python I tried his configure [...]