Python, Readline, and Mac OS X


Python, Readline, and Mac OS X

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 module for Python.
To install (this is one command):

curl -s |
gzip -d -c |
sudo cat > /Library/Python/2.3/

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!

10 Replies to “Python, Readline, and Mac OS X”

  1. Two words:

    1) “Thank”
    2) “You!”

    I really wish OSX came with readline, but I understand its a GPL issue. IPython also works better with readline.

  2. Thank you very, very much.
    I also had to put it in …/site-packages, and it works wonderfully.
    However, I also have an Intel Mac.
    Could you please make an Intel version or let me know where to get the source and how to compile it?
    I’m still suffering from “switch” pains. Switching from Linux, that is.

    Thanks a lot

  3. I’m running OS X 10.5.3, and was running into problems installing readline. After running configure, I ran make and got this error:

    Target: i686-apple-darwin9
    Configured with: /var/tmp/gcc/gcc-5465~16/src/configure –disable-checking -enable-werror –prefix=/usr –mandir=/share/man –enable-languages=c,objc,c++,obj-c++ –program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ –with-gxx-include-dir=/include/c++/4.0.0 –with-slibdir=/usr/lib –build=i686-apple-darwin9 –with-arch=apple –with-tune=generic –host=i686-apple-darwin9 –target=i686-apple-darwin9
    Thread model: posix
    gcc version 4.0.1 (Apple Inc. build 5465)
    i686-apple-darwin9-gcc-4.0.1: -compatibility_version only allowed with -dynamiclib
    make[1]: *** [libreadline.5.2.dylib] Error 1
    make: [shared] Error 2 (ignored)

    My solution was to use a slightly different install process:

    make static
    sudo make install-static

  4. On 10.5.5 with Python 2.5.1, the above install-static directions didn’t work for me. I didn’t get any errors, but it didn’t work. I tried logging out and back in, but no luck.

  5. And ya’ll still don’t read – these instructions are Mac OS X circa 10.3. Doesn’t apply to 10.4+ like it says at the top of the page!

Comments are closed.