Muffinresearch Labs by Stuart Colville

Compiling mod_python for MAMP | 23 Comments

Posted in Code, Linux/Unix on 20th December 2006, 12:40 am by

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

  • http://jeffcroft.com Jeff Croft

    Welcome to the club. :)

  • http://http:/www.shepherdweb.com/ Shane Shepherd

    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.

  • http://nefariousdesigns.co.uk Tim Huegdon

    What about XAMPP?

  • http://muffinresearch.co.uk Stuart Colville

    What about it? :-)

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

    Merry Christmas!

  • http://sedmil.com Foad

    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!

  • http://muffinresearch.co.uk Stuart Colville

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

  • john chapnick

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

  • stasiana

    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.

  • Timothy Chambers

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

  • Toby

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

  • http://gregturner.org/ Greg Turner

    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.

  • jim

    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!

  • Anton

    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

  • Seb Barre

    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…

  • Alex Zavatone

    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.

  • http://aralbalkan.com Aral Balkan

    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.

  • Pingback: Django on OS X - Getting started — blog.bracewell.org

  • Pingback: Django on MAMP Part2 compiling mod_wsgi — blog.bracewell.org

  • AngelProg

    Hello !
    I’have compiled mod_python 3.3.1 from Apache 2.0.59 for Mac Intel.
    Like Stuart, I had to compile Apache myself, the version in MAMP 1.7.1 is buggy.
    Here is my mod_python.so module already compiled for Intel.

  • http://richwerk.com/ richwerk.com

    AngelProg’s binary works great for me on OSX 10.5.6/Mac Pro / Intel. I just needed to install the mod_python libraries for Python.

    Like so…

    ./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/bin/python
    make
    sudo make install_py_lib

  • mnvdk

    Anyone got any experience getting mySQLdb and MAMP working together? I’ve been trying to get this to work, but have not succesfully gotten mySQLdb (mysql-python) to recognize my MAMP installation of mySQL…

    Any help would be appreciated.

  • http://sonique54.Free.fr/spmpt/ sonique6784

    You can also try this package : SPMPT, http://sonique54.Free.fr/spmpt/ , the easier way to get Python, mod_python, subversion and Trac, working on MAMP installtion.

  • Fabricio

    good excerise but I was wondering if anyone knows how to get python working on XAMPP/LAMP (ubuntu)

    thanks.

GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Ubuntu: add-apt-repository: command not found|(3)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

© Copyright 2004-12 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.496s.