【问题标题】:ipython complaining about readlineipython 抱怨 readline
【发布时间】:2011-11-14 14:08:07
【问题描述】:

当我在我的 osx 上安装 ipython 并运行它时,我收到以下警告:

 /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'

我已经安装了readline,不要使用原来安装在/Library/Frameworks/Python.framework/Versions/2.7/bin/python$的系统python。 /usr/bin/python 指向 2.7 版本,如下所示

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

我已阅读 Python sys.path modification not working 中的问题 - 我将 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline-6.2.1-py2.7.egg-info 添加到 /Library/Frameworks/Python.framework/Versions/2.7/bin/ipython 中,现在它看起来像这样:http://pastebin.com/raw.php?i=dVnxufbS

但我无法弄清楚为什么会出现以下错误:

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")

我不认为上述路径是一个问题,我的目标是让 ipython 正常工作而不会抱怨 readline,即使它已正确安装和导入。

【问题讨论】:

标签: python


【解决方案1】:

当 pip 安装 readline 时,它​​永远不会被导入,因为 readline.so 进入 site-packages,它最终位于 libedit System one 之后,位于 lib-dynload(OSX Python 路径顺序非常奇怪)。 easy_install -a readline 实际上会安装可用的 readline。

因此,您可以使用 easy_install,或者使用 pip 并在您的 PYTHONPATH/sys.path 中使用 pip 和 muck about(这基本上意味着:不要使用 PIP)。

关于 IPython 列表的更多详细信息(尽管实际上没有任何关于此问题的 IPython 特定内容):http://mail.scipy.org/pipermail/ipython-user/2011-September/008426.html

编辑:关于 virtualenv 的额外说明。

virtualenv

【讨论】:

  • 此答案的未来读者请注意:如果您已经尝试过 pip install readline 并且没有成功,那么您实际上需要使用 easy_install -a readline。如果没有 -a,看起来 easy_install 会意识到你已经有了一个 pip 安装的 readline,并且什么也不做。 -a 强制它进行完全重新安装。
  • 不幸的是,这个解决方案以及 SO 上的所有其他解决方案都对我不起作用 :( 我已删除 readline,重新安装它,卸载 iPython,直到重新安装 readline,完成它在 virtualenv 中,没有完成,使用easy_install-2.7 等等等等等等 - 我正在运行 OS X 10.8.2。如果有人使用 OS X 10.8.2(愚蠢的 Apple)实现了这一点,会你介意@-ing我的解决方案。
  • @minrk - 谢谢。我发现了我的烦恼的原因;虽然我很容易正确安装readline,但我仍然在virtualenv中安装iPython(我通常这样做,只是为了将非必要工具与我的全局Python安装隔离开来)-当我停用我的virtualenv并pip全局安装iPython时它工作
  • 就我而言,我在 virtualenv 中运行 ipython;显然,我还必须在那个 virtualenv 中运行easy_install -a readline
  • readline 的 Python 包已重命名为 gnureadline,以避免与 stdlib readline 的名称冲突。 IPython >= 2.0 依赖于 OS X 上的这个包,所以pip install --upgrade ipython 会得到正确的 readline,一切都应该是愉快的。
【解决方案2】:

如果您不介意使用 PYTHONPATH,可以通过以下方法摆脱该讨厌的警告:

# 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

如果你使用 Django,你可以把它放在你的 site-packages/django/core/management/commands/shell.py 的 ipython 方法中,这样当你运行 ./manage.py shell 时它就会运行。

【讨论】:

    【解决方案3】:

    对这个答案的未来读者的补充说明。

    就我而言——运行 MacPorts 安装的 IPython——/opt/local/bin/ 中有多个版本的 easy_install,但没有指向最新版本的非版本化符号链接。执行easy_install-2.7 -a readline 有效。

    【讨论】:

      【解决方案4】:

      我也在使用 brew 安装 ipython 并且我遇到了类似的问题。

      ⚡ 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)
      

      解决方案:

      ⚡ 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
      

      结果:

      ⚡ 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
      

      【讨论】:

        猜你喜欢
        • 2011-12-30
        • 2012-07-27
        • 2022-01-10
        • 2012-01-28
        • 2014-06-27
        • 1970-01-01
        • 1970-01-01
        • 2018-01-19
        • 2013-01-16
        相关资源
        最近更新 更多