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.