Python, Mac OS X, and Readline.

Due to the political manifesto that is the GPL, Python on Mac OS X does not ship with the readline module.

This is hugely annoying. Interactive command line python is pretty close to useless without basic history and editing commands.

It is easy enough to fix. Would be easier if I didn’t also want to use the latest libreadline; version 5.1.

Either mount this in the Finder or:

svn co

From there, follow the instructions in the README. It definitely works with the stock Python on Mac OS X Intel. Should work for PPC, too.

It will likely also work for Python 2.4, but I haven’t tested it. If not, copying the readline.c from Python 2.4 into the readline-0.0.0 directory.

As Paul said, check out iPython. It offers an incredible interactive mode with full blown object introspection, including integrated documentation. I use it when I remember (thanks fro the reminder), but I also avoid it when doing examples for others or generating doctest test cases.


– added iPython info

– fixed stupid typo

Deprecated: link_pages is deprecated since version 2.1.0! Use wp_link_pages() instead. in /srv/www/friday/bbum/wp-includes/functions.php on line 4713

11 Responses to “Python, Mac OS X, and Readline.”

  1. Paul Veerasingam says:


    Instead of adding readline to Python, try IPython instead:

    It’s an interpreter for python that supports readline, tab-completion for method names, colors, etc.
    It’s great for testing stuff out!

  2. bbum says:

    iPython is pretty amazing, but it is also considerably more complex than and adds a lot of verbosity over the standard python command line. I seem to end up switching back and forth between the two (when I remember to use ipython).

    Unless I’m mistaken, you can’t use iPython to generate doctest compatible tests. doctest is just too cool; go to the interactive prompt, interact with your objects, save the transcript somewhere, remove any garbage, and feed it all through doctest to ensure that the test behaves the same in the future….

  3. Cameron Hayne says:

    After the “hugely annoying” in the intro, when you wrote: “Would be easier if I didn’t also want to sue the latest libreadline”, I actually thought you were talking about legal action.
    Then I realized it was just a typo.

  4. Donovan Preston says:

    easy_install readline
    easy_install ipython


  5. Tim says:

    What about libedit, the NetBSD readline replacement that ships with Darwin? Can Python be built to use it?

  6. Paul Veerasingam says:

    Thanks for introducing me to doctest! Finally, an easy way to write simple unit tests without resorting to the unittest module.

    You’re right, IPython’s output doesn’t look like the output from a standard Python interpreter, so it is incompatible with doctest docstrings. But it’s so convenient for getting the lowdown on modules/classes etc.

    Instead of ‘dir(objname)’, you can just type ‘objname.’ and you get a list of methods. To find out how to use a method, all you have to do is type ‘objname.method?’ and the object dictionary, method signature, and docstring pops out. The exception messages in IPython are also more descriptive than in the standard Python interpreter.

    But you’re right. The Python interpreter comes standard with every Python installation and it’s easy to use. Guido himself prefers the standard interpreter to IPython.

  7. bbum’s weblog-o-mat » Blog Archive » AppleScript for the rest of us says:

    […] Furthermore, I can use appscript from within the command line interpreter (read this first to make sure the command line python interpreter is actually useful). […]

  8. tyler says:

    Thanks for this tip on getting history for the command line python. not having this was driving me bonkers!

  9. Nicko says:

    Thank you for that. I just got a Intel iMac and realised that I was going to have to finally update my Python readline implementation from way-back. Now I don’t need to! Thank you BBum!

  10. The Infotainment Telesector / Archive / Alas and Alack says:

    […] Bumgarner on fixing readline support in Mac Python. I’ve never run into this as I use the fine packages over at; a lot of my code […]

  11. JamieC says:

    Thankyou, following the readme worked like a charm on my macbook pro with Python 2.4.3.

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=""> <s> <strike> <strong>