November 26, 2006

Compiling readline support for Python on MacOSX

Since ages it has been impossible to build Python from the sources with readline support out-of-the-box. The reason seems to be an outdated or broken version of libreadline that ships with MacOSX. To resolve this issue you have to install Darwinports and install readline from the sources. However configure won't pick up this installation automatically. Usually it is sufficient to specify the location of additional header files and libraries through the CFLAGS and LDFLAGS environment variables however that also did not work. I ended up hacking the generated Makefile. After modifiying the CC definition to

CC = gcc -I/opt/local/include -L/opt/local/lib

I was able to compile and install Python 2.4 and 2.5 with working readline support. It's a hack - but a hack that actually works.

Update for Leopard:

  • after running configure you have to edit
  • search for "if do_readline:"
  • add do_readline = True before the if-statement