Tuesday, November 8, 2011

OS X Terminal screwed up command history in iPython

I was getting some weird behaviour in ipython (0.11) in a OS X (10.6.8) Terminal window. When I used the up arrow to access the commandline history, all long lines (and even some short lines) were screwed up - the text wrapping was wrong. Others have noticed the same thing and it turns out the solution is to re-install readline (which requires Xcode to compile it):

sudo pip install readline
Turns out on Lion with Xcode 4.2, the package downloads and installs without errors but doesn't actually fix the problem. If you download and install using the egg (of the same version?! 6.2.2) it works fine.
sudo easy_install readline-6.2.2-py2.7-macosx-10.7-intel.egg
Update: Just noticed this message on starting ipython on Mountain Lion, and 'sudo easy_install readline' works.
******************************************************************************
libedit detected - readline will not be well behaved, including but not limited to:
   * crashes on tab completion
   * incorrect history navigation
   * corrupting long-lines
   * failure to wrap or indent lines properly
It is highly recommended that you install readline, which is easy_installable:
     easy_install readline
Note that `pip install readline` generally DOES NOT WORK, because
it installs to site-packages, which come *after* lib-dynload in sys.path,
where readline is located.  It must be `easy_install readline`, or to a custom
location on your PYTHONPATH (even --user comes after lib-dyload).
******************************************************************************

No comments: