Muffinresearch Labs by Stuart Colville

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!

Post Tools

Comments: Add yours

1. On December 20th, 2006 at 5:37 am Jeff Croft said:

Welcome to the club. :)

2. On December 21st, 2006 at 3:38 pm Shane Shepherd said:

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.

3. On December 24th, 2006 at 12:56 am Tim Huegdon said:

What about XAMPP?

4. On December 26th, 2006 at 7:54 pm Stuart Colville said:

What about it? :-)

You can download binaries for Win32 from here http://www.apache.org/dist/httpd/modpython/win/

Merry Christmas!

5. On January 16th, 2007 at 10:59 am Foad said:

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!

6. On January 16th, 2007 at 11:06 am Stuart Colville said:

@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.

7. On March 4th, 2007 at 11:03 pm john chapnick said:

do you have a more updated mod_python to work with latest mac python ??

8. On September 21st, 2007 at 4:22 pm stasiana said:

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.

9. On October 2nd, 2007 at 11:38 am Timothy Chambers said:

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”.

10. On November 23rd, 2007 at 5:19 pm Toby said:

Thanks so much for the download link! Your a live saver!

11. On December 10th, 2007 at 1:57 pm Greg Turner said:

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.

12. On December 18th, 2007 at 9:37 pm jim said:

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!

13. On December 19th, 2007 at 10:48 pm Anton said:

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

14. On January 4th, 2008 at 11:12 pm Seb Barre said:

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…

15. On March 11th, 2008 at 9:06 pm Alex Zavatone said:

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.

16. On March 26th, 2008 at 5:41 pm Aral Balkan said:

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.

17. On April 3rd, 2008 at 12:45 am Django on OS X - Getting started — blog.bracewell.org said:

[...] 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 [...]

18. On April 20th, 2008 at 6:57 pm Django on MAMP Part2 compiling mod_wsgi — blog.bracewell.org said:

[...] and unpacked using tar xvzf mod_wsgi-2.0.tar.gz Cribbing Stuart Colville’s post on compiling mod_python I tried his configure [...]







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Standalone mac battery charger|(0)

Got a spare mac battery? I’ve often wondered why up until now no-one’s produced a standalone charger so that you can charge batteries without having to plug them into the mac. Fortunately Fastmac.com have produced a standalone charger that allows you to do just that. and it’s compatible with iBooks, Powerbooks, macbooks and Macbook Pros. It’s also 110/200v. Exactly what I was looking for!

Django Admin Ominigraffle Stencil|(0)

Colleague Alex Lee has created a nice stencil for omingraffle with the Django Admin UI components, perfect for wireframing customised admin screens. For more details and to download the stencil see Alex’s Blog csensedesign.co.uk

Photos on Flickr

© Copyright 2004-08 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by 1&1 This page was baked in 1.353s.