ipython complaining about readline
Asked Answered
H

4

26

When I install ipython on my osx and run it, I get the following warning:

 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
 site-packages/IPython/utils/rlineimpl.py:96:
 RuntimeWarning: Leopard libedit detected - readline will not be wel
 behaved including some crashes on tab completion, and incorrect
 history navigation. It is highly recommended that you install
 readline, which is easy_installable with: 'easy_install readline'

I have have installed readline, and do not use the system python that was originally installed in /Library/Frameworks/Python.framework/Versions/2.7/bin/python$. The /usr/bin/python points to version 2.7 as shown below

uname -a
Darwin macbook.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 
16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

$sudo pip install readline ipython

$ipython --version
0.11

$/usr/bin/python --version # 
Python 2.7.1 

$which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

I have read the question in Python sys.path modification not working - I added /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline-6.2.1-py2.7.egg-info to the /Library/Frameworks/Python.framework/Versions/2.7/bin/ipython so that it now looks like this: http://pastebin.com/raw.php?i=dVnxufbS

but I cannot figure out why I am getting the following error:

File
"/Library/Frameworks/Python.framework/Versions/2.7/bin/ipython",
line 9
sys.path.insert(0,"/Library/Frameworks/Python.framework/Versions/2.7/lib/
python2.7/site-packages/readline-6.2.1-py2.7.egg-info")

I do not think the above path is an issue, and my goal is to get ipython to working without complaining about readline even though it is installed and imports correctly.

Hearn answered 11/9, 2011 at 0:26 Comment(2)
Tab completion does work when I go into ipython inspite of the warning message. So perhaps this means that I can ignore the warning?Hearn
After looking at this a little more, I came across the a post bradmontgomery.net/blog/fix-leopard-libedit-detected that solved my problem.. I had to run "easy_install -a readline" and that made python read the latest installation of readline and this got rid of the problem. More details here:groups.google.com/forum/#!topic/python-virtualenv/BEQAurh9EZw/…. I am not sure how to close out this questions since I have found my own answer.Hearn
M
41

When pip installs readline, it will never be imported, because readline.so goes in site-packages, which ends up behind the libedit System one, located in lib-dynload (OSX Python path order is very odd). easy_install -a readline will actually install usable readline.

So you can either use easy_install, or use pip and muck about with your PYTHONPATH/sys.path (which essentially means: DO NOT USE PIP).

A bit more detail on the IPython list (though there really isn't anything IPython-specific about this issue): http://mail.scipy.org/pipermail/ipython-user/2011-September/008426.html

EDIT: extra note about virtualenv.

There is a bug in virtualenv < 1.8.3, where readline would not be properly staged when you create an env.

Mayorga answered 11/9, 2011 at 7:37 Comment(10)
Note to future readers of this answer: if you've already tried pip install readline and that didn't work, you'll actually need to do easy_install -a readline. Without the -a, it looks like easy_install will realize that you've already got a pip-installed readline, and not do anything. The -a forces it to do a full re-install.Getaway
Unfortunately, this solution, along with all others on SO didn't work for me :( I've removed readline, re-installed it, uninstalled iPython until readline was reinstalled, done it in a virtualenv, done it without, used easy_install-2.7, etc., etc., etc. - I'm running OS X 10.8.2. If anyone has achieved this using OS X 10.8.2 (stupid Apple), would you mind @-ing me with the solution.Cuda
@Cuda yup, I can confirm that easy_install -a readline works on 10.8.2. If you are in a virtualenv, you need to make sure you have virtualenv ≥ 1.8.3 (11/2012), which fixes an issue where readline would not be included in your envs.Mayorga
@Mayorga - thanks. I discovered the cause for my troubles; while I was easy_installing readline properly, I was still installing iPython in a virtualenv (I usually do that, just to segregate non-essential tools from my global Python install) - when I deactivated my virtualenv and pip installed iPython globally it workedCuda
@Mayorga - it may be worth changing the ipython startup message to include the -a.Pyromania
In my case, I was running ipython in a virtualenv; apparently, I must also then run easy_install -a readline in that virtualenv as well.Lodger
Actually this is a mess on Mavericks once again. I'm tired of this situation and installed bpython.Ericson
And this is a mess, because easy_install tries to install Python readline package 6.2.4.1 (not the latest 6.3.3!), which tries to build with gcc-4.0, which isn't supported on Mac OS X 10.9! I'm getting really tired of this situation and installed bpython, which can be installed with either Macports sudo port install py27-bpython or pip install bpython!Ericson
The Python package for readline has been renamed to gnureadline, to avoid the name conflict with stdlib readline. IPython >= 2.0 depends on this package on OS X, so pip install --upgrade ipython will get proper readline, and everything should be happy.Mayorga
easy_install -a readline fixed my global python, thanks! I didn't manage to fix my virtualenv, so I blew it away and recreated it.. sorted!Haughay
A
1

If you don't mind mucking around with your PYTHONPATH, here's how you can get rid of that pesky warning:

# move site-packages to the front of your sys.path
import sys
for i in range(len(sys.path)):
    if sys.path[i].endswith('site-packages'):
        path = sys.path.pop(i)
        sys.path.insert(0, path)
        break

If you're using Django, you can put this in the ipython method of your site-packages/django/core/management/commands/shell.py so that it runs when you run ./manage.py shell.

Anstus answered 18/6, 2013 at 2:15 Comment(0)
B
0

Additional note to future readers of this answer.

In my case -- running a MacPorts installation of IPython -- there were several versions of easy_install in /opt/local/bin/, but no non-versioned symlink pointing to the most current. Performing easy_install-2.7 -a readline worked.

Balloon answered 18/4, 2012 at 15:55 Comment(0)
W
0

I am also using brew installed ipython and I had a similar issue.

⚡ easy_install-3.7 -a readline
Searching for readline
Reading https://pypi.org/simple/readline/
Download error on https://pypi.org/simple/readline/: unknown url type: https -- Some packages may not be found!
Couldn't find index page for 'readline' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: unknown url type: https -- Some packages may not be found!
No local packages or working download links found for readline
error: Could not find suitable distribution for Requirement.parse('readline') (--always-copy skips system and development eggs)

Solution:

⚡ brew install readline
Updating Homebrew...
Warning: readline 7.0.5 is already installed, it's just not linked
You can use `brew link readline` to link this version.
⚡ brew link readline
Warning: readline is keg-only and must be linked with --force
⚡ brew link readline --force
Linking /usr/local/Cellar/readline/7.0.5... 16 symlinks created

Result:

⚡ ipython
Python 3.7.2 (default, Dec 27 2018, 07:35:06)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
>>> ~/.pyrc loaded successfully
Whisenhunt answered 7/1, 2019 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.