Python, Readline, and Mac OS X

New system. New Python installation. Need readline. Now!

Because of the weblog ‘refresh’, this has fallen out of cache. Python’s interactive interpreter supports readline style command line editing. That is, a good chunk of the basic emacs text editing/navigation commands will work at the interpreter prompt if the readline module is available. Because it is tainted by the GPL, Mac OS X does not ship with the readline library.

Building libreadline is trivial. It can be downloaded from GNU’s ftp site. If you do decide to build libreadline, consider building it as a statically linked library via ./configure –disable-dynamic –enable-static. Subsequently, any applications linked against readline will not require the readline dynamic library to be preinstalled on the target system.

That is exactly how I built the readline.so module for Python. To install (this is one command):

curl -s http://www.pycs.net/bbum/2004/1/21/readline.so.gz |\
	gzip -d -c |\
	 sudo cat > /Library/Python/2.3/readline.so

The source to the module is also available. It isn’t very interesting in that it just contains the readline.c module extracted from the Python 2.3.x source tree and bundled up into a standard distutils managed module.

Ahh…. readline at the Python interpreter. One more bit of sanity restored to my computing environment.

Update: Bob Ippolito pointed out that everything is included in Panther to install the readline module without preinstalling the MacPython Panther extensions. Not only that, but can be done with a one liner:

python `python -c "import pimp; print pimp.__file__"` -i readline

Shortly, it will be “google-able”, making it the best solution yet.

Thanks Bob!



Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>