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.
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?
Jacob said this on February 15th, 2008 at 12:51 am
Never mind, I just had to blow away the dist directory and start over.
Jacob said this on February 15th, 2008 at 2:30 pm
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?
sewi said this on March 7th, 2008 at 5:43 pm
Following these instructions I still get the sigterm when apache starts up under leopard. Any ideas?
ken said this on July 22nd, 2008 at 4:57 pm
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!
kev said this on August 26th, 2008 at 11:05 pm