IPython on Mac OS X 10.5 Leopard

Some interesting things have happened recently that have caused me to spend way too much time writing Python code:

  • Google App Engine was release with native support for pure Python web applications. It’s now really easy to write and deploy Python applications that are extremely scalable on top of a solid (and portable)  infrastructure.
  • Apple released Mac OS X 10.5 Leopard, and included support for Python as a first-class citizen in its Xcode development tool (which lets you develop with Xcode/Interface Builder pretty seamlessly), in its ScriptingBridge (which allows you to access AppleScript enabled applications using the goodness of Python, and not the confusingness of AppleScript), and allowing for very easy interaction with Cocoa objects (Apple’s GUI programming framework).

The net result of all this is that I’ve been spending a lot of time in Python. Surprised the hell out of me, but it’s the truth.

I have found the IPython command-shell particularly useful. It’s very well done, and has excellent documentation. Problem is, it doesn’t work so well on Mac OS X 10.5 Leopard. Your screen gets scrogged because of a Readline conflict (see the video). Here’s my cookbook for getting it to work – it’s way easier than all the other documents on the Internet lead you to believe.

  1. Installing IPython on Mac OS X is actually quite easy with the following command:
    sudo easy_install ipython
  2. Execute the command to load the right Readline library:
    sudo easy_install -f http://ipython.scipy.org/dist/ readline

That’s it. Let me know if that didn’t work for you.

Now, if you could only get Apple to include Python support in the iPhone SDK

23 Responses to “IPython on Mac OS X 10.5 Leopard”


  • Worked for me, thanks!

  • Worked for me too… Thanks for posting this

  • Where do I type “sudo etc”

    in to IDLE ?

    If so it just tells me invalid syntax.

    Thanks

  • Thank you for the commands!!
    Greetings from Mexico!

  • Worked like a charm, you da man! Thanks!

  • Well, it almost works for me. Problem is that the “u” key doesn’t function; when I press it within ipython, nothing happens. The capital “U” key does work. If I start ipython with “ipython -noreadline” the “u” key works again but, of course, I lose tab completion. Sigh.

    Any ideas what the problem is here?

    Thanks in advance,
    Gary

  • Cool. ipython rules. However, the readline part failed for me because apparently I don’t have gcc or make?

  • ^ install xcode/dev tools

  • worked. excellent. thank you.

  • Hi.

    The readline install did not work for me. I’ve been trying to install readline several ways, all to no effect.

    When I do your suggested install, I get:
    Tonys-Mac-2:127:~/pythonSuperpack $ sudo easy_install -f http://ipython.scipy.org/dist/ readline
    Password:
    Searching for readline
    Best match: readline 2.5.1
    Processing readline-2.5.1-py2.5-macosx-10.5-fat.egg
    readline 2.5.1 is already the active version in easy-install.pth

    Using /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/readline-2.5.1-py2.5-macosx-10.5-fat.egg
    Processing dependencies for readline
    Finished processing dependencies for readline

    Which seems OK, until I run ipython:

    Tonys-Mac-2:129:~/pythonSuperpack $ ipython
    WARNING: Readline services not available on this platform.
    WARNING: The auto-indent feature requires the readline library
    IPython 0.9.1 [on Py 2.5]

    Any suggestions? Thanks for your help.

    -Tony

  • Hello.

    This time, I removed the readline stuff in /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages and executed your readline build line:
    sudo easy_install -f http://ipython.scipy.org/dist/ readline

    The build failed. Lots of errors, such as:
    ============ Building the readline extension module ============

    Modules/readline.c: In function ‘py_remove_history’:
    Modules/readline.c:307: warning: assignment makes pointer from integer without a cast
    Modules/readline.c: In function ‘py_remove_history’:
    Modules/readline.c:316: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target typeModules/readline.c:307: warning: assignment makes pointer from integer without a cast

    Modules/readline.c:318: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    Modules/readline.c:316: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    Modules/readline.c:318: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    Modules/readline.c: In function ‘py_replace_history’:
    Modules/readline.c:344: warning: assignment makes pointer from integer without a cast
    Modules/readline.c:353: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    Modules/readline.c:355: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    Modules/readline.c: In function ‘get_current_history_length’:
    Modules/readline.c:459: error: ‘HISTORY_STATE’ undeclared (first use in this function)
    Modules/readline.c:459: error: (Each undeclared identifier is reported only once
    Modules/readline.c:459: error: for each function it appears in.)
    Modules/readline.c:459: error: ‘hist_st’ undeclared (first use in this function)
    Modules/readline.c: In function ‘on_completion’:
    Modules/readline.c:643: error: ‘rl_attempted_completion_over’ undeclared (first use in this function)
    Modules/readline.c: In function ‘flex_complete’:
    Modules/readline.c:681: error: ‘rl_compentry_func_t’ undeclared (first use in this function)
    Modules/readline.c:681: error: syntax error before ‘)’ token
    Modules/readline.c:681: warning: return makes pointer from integer without a cast
    Modules/readline.c: In function ’setup_readline’:
    Modules/readline.c:706: warning: passing argument 2 of ‘rl_bind_key_in_map’ from incompatible pointer type
    Modules/readline.c:707: warning: passing argument 2 of ‘rl_bind_key_in_map’ from incompatible pointer type
    Modules/readline.c: In function ‘readline_until_enter_or_signal’:
    Modules/readline.c:758: error: ‘rl_catch_signals’ undeclared (first use in this function)
    Modules/readline.c:761: warning: passing argument 2 of ‘rl_callback_handler_install’ from incompatible pointer type
    Modules/readline.c: In function ‘call_readline’:

    Any thoughts? Thanks for your help. I have Mac OS X with Leopard 10.5.5

    -Tony

  • Didn’t work for me.

    In the beginning of the build, all goes well:

    Best match: readline 2.5.1
    Downloading http://ipython.scipy.org/dist/readline-2.5.1.tar.gz
    Processing readline-2.5.1.tar.gz
    Running readline-2.5.1/setup.py -q bdist_egg –dist-dir /tmp/easy_install-ecniWD/readline-2.5.1/egg-dist-tmp-hEgh0g

    ============ Building the readline library ============

    readline-5.2/
    (…)
    Beginning configuration for readline-5.2 for i386-apple-darwin9.5.0
    (…)

    But in the “Building the readline extension module” phase it gives many warnings and errors. The complete output here:
    http://alexsm.googlepages.com/readline-build.txt

  • for non system wide install:
    mkdir -p ~/.python/lib/python2.5/site-packages
    echo “PYTHONPATH=$HOME/.python/lib/python2.5/site-packages” >> ~/.bash_profile
    echo “export PYTHONPATH” >> ~/.bash_profile

    log out and login from the shell
    than run

    easy_install –prefix $HOME/.python http://ipython.scipy.org/dist/ipython-0.9.1-py2.5.egg
    easy_install –prefix $HOME/.python -f http://ipython.scipy.org/dist/ readline

  • Got the same errors as Alex and Tony when installing the readline module.

  • Zogzog all,
    I was having the same problem with:
    WARNING: Readline services not available on this platform.
    WARNING: The auto-indent feature requires the readline library

    I made sure that readline was installed with:
    sudo easy_install -f http://ipython.scipy.org/dist/ readline

    and it didn’t work.
    Then I checked in /Library/Python/site-package/
    and I saw a pyreadline*.egg that I removed (cf. http://lists.ipython.scipy.org/pipermail/ipython-user/2008-May/005402.html)

    Then ipython was happy again.

    I hope that helps.
    Seb

  • How do I get easy_install to work? I’ve tried downloading setuptools but cannot get the script to run. All the information I have found on it is pretty vague, and I’m not very familiar with Python. I am trying to get iPython, but first I need to succesfully run easy_install. Any ideas?

  • I had the same problem as Alex, lots of gcc errors and exits with “command ‘gcc’ failed with exit status 1″.

    Using Leopard, on a brand new mpb with dev tools / xcode installed.

    what am I doing wrong?

  • Running the command didn’t solve the problem but I found that I had some other readline files, including one in lib-dynload. So I deleted all those and ran the command again.

    It worked, thanks!

  • It didn’t work for me, the readline module doesn’t compile – I believe I have all of the dependencies. I’m running Mac OS X 10.5.6, Python 2.6 installed via darwin ports.

    Here’s the error message from easy_install:

    http://pastebin.com/fe2d63b5

  • I got the exact same warnings and errors that Alex got.

    I’m running Leopard 10.5.6.

    Any thoughts, Brian?

  • I get exactly the same error as Alex (GCC failure), however I have macports installed and:

    sudo port install readline-5

    makes everything work fine for me.

  • Didn’t work for me either, exactly the same problem as Alex.
    The solution here seems to work for me though:
    http://hurley.wordpress.com/
    Basically just copy the egg directory by hand to /Library/Python/2.5/site-packages
    and edit /Library/Python/2.5/site-packages/easy-install.pth

  • Question:

    I have a MacBook with 10.5.6 and I followed all the steps but I cannot get any tab-completion or emacs-like key strokes to work with ipython. The commands and shortcuts work fine with the terminal, but stop working after ipython is loaded. Help?

    M

Leave a Reply