Sunday
27
Jun 2004

Compile mod_python on Mac OS XHOWTO Compile mod_python on Mac OS X

(12:19 am) Tags: [Software, How do I...]

I just got mod_python 3.1.3 up and running on Apache 2.0.49 on Mac OS X 10.3.4. Caveats: this is my own custom built from the source Apache, and you will need Fink installed with python 2.3 installed. If fink is already installed, just do a fink install python-23. Now the last step before we get started: if you open a terminal window, and type ‘python’, do you get python 2.3.3 (fink’s), or 2.3 (apple’s)? It is imperative that you end up opening the fink version of python (for dynamic loading reasons I won’t get into here). If you are not getting the fink version, try something like:

sudo ln -s /sw/bin/python2.3 /sw/bin/python
I compiled my apache with:

./configure –enable-so –with-mpm=worker
make
sudo make install (installs to /usr/local/apache2)

Then I compile and install mod_python:

./configure \
–with-apxs2=/usr/local/apache2/bin/apxs \
–with-python=/sw/bin/python2.3
make
sudo make install

Now, edit the httpd.conf to add the following line (mod_python does NOT do it for you)”

LoadModule python_module modules/mod_python.so

Now, start or restart apache:

/usr/local/apache2/bin/apachectl start (or restart)

Note that I used the full path here as Mac OS X ships with an apachectl in /usr/sbin.

That should be it. Follow the examples in the documentation at modpython.org and you should have a successful mod_python install.

Gotchas I encountered mainly have to do with file permissions mainly. If the nobody user cannot see the files you want to use, then they will not be served. I moved all of my development out of my home directory, since I did not want to mess with perms on my home directory and possibly invalidate my use of FileVault.

Happy Pythoning!!!

Popularity: 23%

8 Responses to “Compile mod_python on Mac OS XHOWTO Compile mod_python on Mac OS X”

  1. John Raines Says:

    I’m really a newbie to Unix but do want to install mod_python and so I’ve tried to follow your instructions. I put a folder “apache2″ into usr/local and got through those instructions great. Then I put a folder “mod_python” into usr/local and typed in the ./configure command as you have it. I get a message saying that it doesn’t see -with-apxs2 and then it goes off and finds Apple’s apache 1.3, complains and quits. When I look through the directory structure apxs is exactly where your example says it should be. Any ideas?

  2. John Raines Says:

    John-Raines-Computer:/usr/local/mod_python-3.1.3 jrraines$ ./configure -with-apxs2=/usr/local/apache2/bin/apxs -with-python=/sw/bin/python2.3
    checking for gcc… gcc
    checking for C compiler default output… a.out
    checking whether the C compiler works… yes
    checking whether we are cross compiling… no
    checking for suffix of executables…
    checking for suffix of object files… o
    checking whether we are using the GNU C compiler… yes
    checking whether gcc accepts -g… yes
    checking for ar… ar
    checking for a BSD-compatible install… /usr/bin/install -c
    checking whether make sets ${MAKE}… yes
    checking for main in -lm… yes
    checking for gcc option to accept ANSI C… none needed
    checking for an ANSI C-conforming const… yes
    checking your blood pressure… a bit high, but we can proceed
    configure: checking whether apxs is available…
    checking for –with-apxs… no
    checking for apxs in /usr/local/apache/sbin… no
    checking for apxs in your PATH… checking for apxs… /usr/sbin/apxs
    found /usr/sbin/apxs, we’ll use this. Use –with-apxs to specify another.
    checking Apache version… 1.3.29
    configure: error: This version of mod_python only works with Apache 2. The one you have seems to be 1.3.29.
    John-Raines-Computer:/usr/local/mod_python-3.1.3 jrraines$

  3. John Raines Says:

    OK I found it. Your example says -with-apxs2=
    should be -with-apxs=
    now its working. Your page was enormously helpful thanks!!!

  4. Stefan S Says:

    I tried this on Mac OSX 10.4. No problems with the installation, but once I tried to start apache through apachectl, I get the following error message:
    Syntax error on line 233 of /usr/local/apache2/conf/httpd.conf:
    Cannot load /usr/local/apache2/module/mod_python.so into server: cannot create object file image or add library
    s

    Any ideas what the problem here is ?

    (My config is apache 2.0.54, python2.3)

  5. Scott Sanders Says:

    Stefan,
    I have not yet tried it on 10.4, sorry.

  6. Stefan S Says:

    My apology for the last ‘rushed’ post. Was nothing else than a typo in the path.

    I finally got it to work on OS X 10.4, the final issue I run into was that python would pick up it’s lib files from /usr/lib/python2.3 which is part of the mac installation an not the one I did myself (the -with-python option appearently has not effect on the lib paths). After pointing /usr/lib/python2.3 to /sw/lib/python2.3 everything worked well.

  7. Scott Swanson Says:

    The question is, can you get mod_python compiled for the MacOS X (Tiger) Server native httpd and python install?

    I fear there’s no easy (or even medium-hard, or sane) way, but maybe someone’s already gone to the more insane lengths than I have.

  8. Ming Says:

    I built out mod_python. so using the following config:
    ./configure -enable-so -with-apxs2=/Applications/xampp/xamppfiles/bin/apxs
    make
    sudo make install
    Note: I modified two files to pass the compilation:
    1, config.status
    2, src/Makefile
    removed the following words:
    -arch ppc

Leave a Reply