Compiling Python 3.2 with readline support on MacOS X 10.7

This post explains how to compile Python v3.2 including support for the GNU Readline Library on MacOS X 10.7 (Lion), not using tools like MacPorts. One of the problems we try to solve is making history work in the interactive Python interpreter.

Pre-requirement is to have Apple’s XCode installed (check the Appstore).

First, you need a fresh copy of the GNU Readline Library and compile it. At the time of writing, readline v6.2 was the latest. Fire up a Terminal and do the following:

$ tar xzf readline-6.2.tar.gz
$ cd readline-6.2
$ MACOSX_DEPLOYMENT_TARGET=10.7 ARCHFLAGS="-arch x86_64" ./configure --prefix=/opt/local
$ make && sudo make install

Note that you can change the location /opt/local to anything you like, but avoid /usr/lib or other system location.

When readline compiled and installed successfully, compile Python v3.2 as follows:

$ tar xzf Python-3.2.3.tgz
$ cd Python-3.2.3
$ LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" \
    ./configure --prefix=/opt/python/3.2.3
$ make && sudo make install

Note that you might have more arguments to pass to the ./configure if you have special needs. Note also that /opt/python/3.2.3 is where Python will be installed to avoid clashing with the system provided Python installations.

You should now have history support in the Python interpreter:

$ /opt/python/3.2.3/bin/python3
>>> import this
>>>