17

I am using ipython on Mac OS 10.5 with python 2.5.1 (I would actually like to use ipython for 2.6.1, but it doesn't seem to be available?)

I installed ipython via easy_install. It works but is missing gnu readline (needed for nice searching of command line history with ctrl-R, etc.)

I found a blog post and other sources saying this could be fixed by

sudo easy_install -f http://ipython.scipy.org/dist/ readline

However, this leads to build errors in readline.c , particularly undeclared functions like rl_compentry_func_t and rl_catch_signals.

Has anyone seen these errors? Is there another way to get ipython installed with readline?

  • If you want to use vi keys in your ipython, check out http://stackoverflow.com/questions/10394302/how-do-i-use-vi-keys-in-ipython-under-nix/10394328 – gak May 01 '12 at 06:27

6 Answers6

34

To install ipython on Snow Leopard or Lion without using MacPorts, you can simply do:

sudo easy_install readline ipython

(Note that if you use the "pip" to install readline, then ipython won't see the readline library, not sure why).

Edit:

If you had ipython installed remove it with

sudo pip uninstall ipython

or

pip uninstall ipython #for virtualenvs

Then make sure you have installed readline first and reinstall iptyhon

pip install readline ipython

For some reasons, if readline wasn't present during the installation, it will install itself without support for readline or it use the default mac readline.

Tom
  • 22,301
  • 5
  • 63
  • 96
Lorin Hochstein
  • 57,372
  • 31
  • 105
  • 141
  • 4
    There's a discussion on the virtualenv group about the pip problem. (Summary: pip doesn't place its readline in front of the incompatible pre-installed version in sys.path) http://groups.google.com/group/python-virtualenv/browse_thread/thread/044400bab87d119c/0bf2816070524268?show_docid=0bf2816070524268 – Carlton Gibson Aug 10 '10 at 13:15
  • It does work now, if ipython is already installed it won't work. You can add that you need to uninstall ipython. Ipython probably compile without readline or with the mac readline – Loïc Faure-Lacroix Jun 04 '12 at 00:32
  • @LoïcFaure-Lacroix Please feel free to edit my answer accordingly. – Lorin Hochstein Jun 04 '12 at 13:21
13

this worked for me (I'm using python 2.7, for other versions you'll need to edit):

cd /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
sudo mv readline.so readline.so.bak

install readline however you want (pip, homebrew, macports, etc)

pip install -U readline

Success! and it works with virtualenv, and virtualenvwrapper, and no need to modify ipython :)

Jiaaro
  • 74,485
  • 42
  • 169
  • 190
  • 1
    Thanks! Based on this I was able to mend my self-installed but readline-broken Py 2.7 on Snow Leopard. – Jacob Oscarson Feb 27 '12 at 21:07
  • 1
    Worked for me too, simplest way. – zengr Mar 03 '12 at 06:18
  • The sudo mv step is the only thing that fixed the problem for me on Mavericks. After that I did pip uninstall for both followed by 'pip install readline ipython' inside my virtualenv. – Andy Baker Jan 02 '14 at 11:31
3

The only working way on MacOS Mavericks is to:

  1. switch to your virtualenv workon myproject_name
  2. delete readline and ipython (if you installed it before) pip uninstall readline ipython
  3. install readline only via easy_install (pip - no work!) easy_install readline
  4. finally install ipython with pip pip install ipython

It's work well on my MacOS and tested a long time.

Anton Danilchenko
  • 2,318
  • 1
  • 25
  • 24
3

You can install everything you need with essentially one command using MacPorts. First download and install MacPorts from http://www.macports.org/.

Then just do the following in the terminal: 1) sudo port -v selfupdate
2) sudo port -v install py26-ipython

That will install python2.6, ipython for python 2.6 and readline for you. The command to start ipython will be located at /opt/local/bin/ipython2.6

hohonuuli
  • 1,974
  • 15
  • 15
  • 2
    Sadly, as macports has fallen out of favor, I don't think this is the ideal solution any longer. Most folks seem to prefer homebrew these days. – Benson Feb 29 '12 at 21:32
  • 1
    Yeah, I agree. In my defense, there was no homebrew when I answered the question. – hohonuuli Mar 12 '12 at 21:18
  • Agreed. It was a great answer, I just thought I'd mention it for folks who stumble on this via google. – Benson Mar 12 '12 at 23:45
1

An alternative if you don't want to use ports. Caution: This is not upgrade safe.

Install ipython and readline as normal:

sudo easy_install -f http://ipython.scipy.org/dist/ readline ipython

Find the full path to your readline egg. For python 2.6 this will probably be:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/readline-2.5.1-py2.6-macosx-10.3-fat.egg

Edit ipython with your favourite text editor:

vim `which ipython`

Before the final line in the file sys.exit, insert:

sys.path.insert(0,'PATH_TO_READLINE_EGG')

Save and exit (:wq).

Check readline is working correct:

ipython
galpin
  • 56
  • 1
0

"I would actually like to use ipython for 2.6.1"

It is available. I'm using it with 2.6.1 on os x. You just need to install the official python 2.6.1 distribution, then install ipython with easy_install.

Vasil
  • 36,468
  • 26
  • 90
  • 114