Peuchele bio photo


Pedí pollo que yo pago la diferencia!

Photo Credit: Wikimedia Commons

Photo Credit: Wikimedia Commons

If you have a Mac OS X Leopard on an Intel platform, and you are interested in installing mod_python using your default apache setup and the python that comes with the Framework, even more if you want to give PyCAPTCHA a try together with mod_python, then check out this post! I’m covering also the installation of required libraries for PyCAPTCHA under Leopard (FreeType2, libjpeg, PIL)


Compile mod_python

If you have Apple’s Xcode installed, compiling mod_python for Leopard to use with the system provided versions of httpd, python, etc. should be as simple as running these commands:

mkdir -p ~/mod_python
cd ~/mod_python
svn co mod_python-trunk
cd mod_python-trunk
./configure --with-apxs=/usr/sbin/apxs
sudo make install
cd test/

Original source

Configure Apache to load mod_python

Open /private/etc/apache2/httpd.conf with your favorite editor and add the following line:

LoadModule python_module libexec/apache2/
Example of how to configure Apache to load a mod_python application

This is just an example, I recommend reading the mod_python manual for more information.

Open /private/etc/apache2/users/username.conf with your favorite editor and add:

Alias / "/Users/username/htdocs/"
<Directory "/Users/username/htdocs/">
	SetHandler python-program
	PythonHandler mod_python.publisher
	# Disable following line when in production
	PythonDebug On
	<Files ~ "\.(gif|jpg|png|ico|js|css)$">
		SetHandler default-handler
	Order allow,deny
	Allow from all

Restart Apache with the command below:

/usr/sbin/apachectl restart


In order to build and install PyCAPTCHA you’ll need to compile, or make sure that you have these required libraries:

  • FreeType2
  • libjpeg
  • PIL (Python Imaging Library)

Let’s see how to set up these libraries under a Leopard / Intel environment.


This library is required for PyCAPTCHA, as far as I know it is already installed with the SDK, to check the directory where the library is installed use the command:

locate libfreetype.dylib

A version of this library should appear under /Developer/SDKs/MacOSX10.5.sdk/usr/X11/


Download jpeg source and uncompress it in any directory, e.g. ~/jpeg-6b then:

cd ~/jpeg-6b
chmod -R 777 *

Edit Makefile and change the following line from:

CFLAGS= -O2 -I$(srcdir)


CFLAGS= -arch ppc -arch i386 -arch ppc64 -arch x86_64 -O2 -I$(srcdir)

Finally, build and install:

sudo make install-lib


Download PIL source and uncompress it in any directory, e.g. ~/imaging-1.1.6 then:

cd ~/imaging-1.1.6

Edit and change the following lines from:


to (note that I’m using the FreeType2 directory discovered previously with the locate command):

    FREETYPE_ROOT = libinclude("/Developer/SDKs/MacOSX10.5.sdk/usr/X11/")

and then following line from:

    JPEG_ROOT = None


    JPEG_ROOT = libinclude("/usr/local")

Locate these lines:

from distutils import sysconfig
from distutils.core import Extension, setup
from distutils.command.build_ext import build_ext

And add the following lines (correctly indented from column 0):

OrigExtension = Extension

def Extension(*args, **kwargs):
    extra_args = ['-arch', 'ppc', '-arch', 'ppc64', '-arch', 'i386', '-arch', 'x86_64']
    kwargs['extra_compile_args'] = extra_args + kwargs.get('extra_compile_args', [])
    kwargs['extra_link_args'] = extra_args + kwargs.get('extra_link_args', [])
    return OrigExtension(*args, **kwargs)

Now proceed to compile and install the library:

sudo python install


Now you are ready to build and install PyCAPTCHA. Checkout the source code from this link and run the following command:

sudo python install

That’s it!