home | talks | photos | about | resume | contact

mod_python on Leopard

Compiling mod_python on Leopard is not as simple as it would appear.

The default install only builds a i386 version that fails when restarting Apache with the error:

httpd: Syntax error on line ** of /Users/*******/Downloads/mod_python-3.3.1/test/conf/test.conf: Cannot load /usr/libexec/apache2/mod_python.so into server: dlopen(/usr/libexec/apache2/mod_python.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/mod_python.so: mach-o, but wrong architecture

The mod_python list has some details on how to make this work but they are just a little incomplete… so here it is, the full version. After you run the configure script you’ll need to change src/Makefile in the following ways:

  • Add “-arch x86_64″ to the end of the LDFLAGS line (no quotes, of course).
  • Add “-arch x86_64″ to the end of the CFLAGS line , otherwise you’ll get the “symbol not found” error.
  • Under the mod_python.so target add the following to the $(APXS) line after the -c but before the $(SRCS) “-Wc,”-arch x86_64″”

That should do it, just make && make install then configure and reload apache (launchctl stop org.apache.httpd && launchctl start org.apache.httpd), you’ll be serving python in no time.

You should be able to adapt this method to build a universal binary with a little research on the proper arch arguments, if you do go ahead and post in the comments what you did.

7 Responses to “mod_python on Leopard”

  1. Thanks for the tip. No problems compiling and installing, but when I add the module to httpd.conf (LoadModule python_module /usr/libexec/apache2/mod_python.so) I get “caught SIGTERM, shutting down” from Apache when I try to start it. Any ideas?

  2. Never mind, I just had to blow away the dist directory and start over.

  3. Perfect idea. When I modify the Makefile I get this response:

    /usr/sbin/apxs -I/Users/petr/Desktop/mod_python-3.3.1/src/include -I/usr/include/apache2 -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c -Wc,”-arch x86_64? mod_python.c _apachemodule.c requestobject.c tableobject.c util.c serverobject.c connobject.c filterobject.c hlist.c hlistobject.c finfoobject.c -arch x86_64,-Wl,-framework,Python -u _PyMac_Error -framework Python -Wl,-F. -lm -framework Python -ldl
    /usr/share/apr-1/build-1/libtool –silent –mode=compile gcc -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/usr/include/apache2 -I/usr/include/apr-1 -I/usr/include/apr-1 ”-arch -I/Users/petr/Desktop/mod_python-3.3.1/src/include -I/usr/include/apache2 -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c -o mod_python.lo mod_python.c && touch mod_python.slo
    i686-apple-darwin9-gcc-4.0.1: ”-arch: No such file or directory
    mod_python.c: In function ‘python_init’:
    mod_python.c:826: warning: initialization from incompatible pointer type
    apxs:Error: Command failed with rc=65536

    I suppose it has something to do with LDFLAGS and i’ve tried almost all combinations but it is not working. Any ideas?

  4. Following these instructions I still get the sigterm when apache starts up under leopard. Any ideas?

  5. I’m getting the same results – SIGTERM. I don’t know why, but the build is still coming from the “copying build/lib.macosx-10.5-i386-2.5/mod_python/util.py -> /Library/Python/2.5/site-packages/mod_python” and I suspect that’s the issue. Any help would be much appreciated!

  6. Note that you can’t copy the third command straight off, wordpress does mangle the quotes. So the correct line to use is:

    -Wc,”-arch x86_64″

  7. I have a first generation MacBook (Core Duo) and here it is not needed to modify the makefile. In fact I get the aforementioned error if I do.

Leave a Reply




DISCLAIMER: The opinions expressed on this website are mine and mine alone, they should not be interpreted as the views of my employers, past or present, my family, my church or my pets. Comments are the property of their posters and I can not be held accountable for those.