简体   繁体   English

Python 2.7中没有Readline支持

[英]No Readline Support in Python 2.7

I'm not getting any readline functionality in my python interactive sessions. 我在python交互式会话中没有获得任何readline功能。 Arrow keys just move the cursor around the screen or print ^[[A etc. Some web searching led me to try to manually import the readline package, but this resulted in the following error: 箭头键只是在屏幕上移动光标或打印^[[A等一些网页搜索让我尝试手动导入readline包,但这导致以下错误:

>>> import readline >>>导入readline
Traceback (most recent call last): Traceback(最近一次调用最后一次):
File "<stdin>", line 1, in <module> 在<module>中的文件“<stdin>”,第1行
ImportError: /opt/readline-6.3/lib/libreadline.so.6: undefined symbol: PC ImportError:/opt/readline-6.3/lib/libreadline.so.6:undefined symbol:PC

I think this is a version-specific problem as this doesn't occur in the 2.6 environment that's on the machine I'm working on by default (I'm working in 2.7.10 in a virtualenv - this is the most recent python 2.7 version I can load on the machine, as far as I'm aware). 我认为这是一个版本特定的问题,因为这不会出现在我正在处理的机器上的2.6环境中(我在2.7.10中的virtualenv工作 - 这是最新的python 2.7据我所知,我可以在机器上加载版本。 It's running linux, by the way - CentOS 6.8. 顺便说一下,它正在运行Linux - CentOS 6.8。

It seems like others have had this problem in some form or another but I can't tell if their solution is out of date (do I need the readline package that has since been deprecated ?) and even if it wasn't I am not sure how to install the fixed version of the package (I'm not very python-savvy yet and I haven't gotten much beyond your basic pip install or conda install ). 看起来其他人已经以某种形式出现了这个问题,但我无法判断他们的解决方案是否已过时(我是否需要已弃用的readline包?)即使不是我也不是确定如何安装固定版本的软件包(我不是很狡猾的知识,我没有超出你的基本pip installconda install )。

How can I resolve this error? 我该如何解决这个错误? If it's not to much to ask, a solution that wouldn't require me to switch from pip to conda would be ideal, as I'm sshing into a machine I don't have full control over and would like to do as much as possible with the tools I already have or can easily install. 如果不是要问的话,一个不需要我从pip切换到conda的解决方案将是理想的,因为我正在进入一台机器,我没有完全的控制权,并且想做的就像可以使用我已经拥有或可以轻松安装的工具。

I was able to resolve this problem (albeit in a somewhat hacky way) by configuring python to import the gnureadline package at startup: 通过配置python以在启动时导入gnureadline包,我能够解决这个问题(尽管有点gnureadline

  1. Create a script, pythonstartup.py , that runs import gnureadline 创建一个脚本, pythonstartup.py ,运行import gnureadline
  2. Modify ~/.bashrc to export the environment variable PYTHONSTARTUP='pythonstartup.py' 修改~/.bashrc以导出环境变量PYTHONSTARTUP='pythonstartup.py'

( Documentation on PYTHONSTARTUP ) (关于PYTHONSTARTUP 文档

Putting import gnureadline in my .pdbrc file made the fix work for pdb sessions too. import gnureadline放入我的.pdbrc文件中也使修复工作也适用于pdb会话。 For some reason it still doesn't work when entering an interactive session after running script from command line with python -i , though. 出于某种原因,在使用python -i从命令行运行脚本后进入交互式会话时仍然无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM