I was wondering if anyone can explain why all of a sudden in Python interactive mode all arrow keys are failing?
我想知道是否有人能解释为什么在Python交互模式下所有箭头键都失败了?
When I press up button for example to go through command history I get "^[[A". Same with any other arrow keys.
当我按下按钮例如通过命令历史记录时,我得到“^ [[A”。与任何其他箭头键相同。
I have no idea why this happened and it was working before (on OS X Snow Leopard). Does anyone know a way to fix this?
我不知道为什么会发生这种情况并且之前有效(在OS X Snow Leopard上)。有谁知道解决这个问题的方法?
Many thanks,
G
4 个解决方案
#1
6
You don't say which Python you are using but the symptoms you mention are indeed usually caused by Python not being built with readline
support. These days Python on OS X can be built to use either the GNU readline
library or the Apple-supplied editline
library (AKA libedit
). You can use the following two commands to show exactly which Python you are using. If that does not help you figure out what is going on, edit your question to show the output from those commands.
你没有说你正在使用哪种Python,但你提到的症状确实通常是由于Python没有使用readline支持构建的。目前,OS X上的Python可以构建为使用GNU readline库或Apple提供的editline库(AKA libedit)。您可以使用以下两个命令准确显示您正在使用的Python。如果这无法帮助您弄清楚发生了什么,请编辑您的问题以显示这些命令的输出。
Here's an example that shows a recent MacPorts Python 2.6 on OS X 10.6:
这是一个示例,显示OS X 10.6上最近的MacPorts Python 2.6:
$ python -c 'import sys;print(sys.version);print(sys.executable)'
2.6.5 (r265:79063, Jul 15 2010, 01:53:46)
[GCC 4.2.1 (Apple Inc. build 5659)]
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
$ otool -L $(python -c 'import readline; print(readline.__file__)')
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/readline.so:
/opt/local/lib/libreadline.6.1.dylib (compatibility version 6.0.0, current version 6.1.0)
/opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
The path prefix /opt/local/
is the default location for MacPorts-installed software and the output from otool
indicates that this Python's readline
module is dynamically linked to the MacPorts-installed GNU readline
library.
路径前缀/ opt / local /是MacPorts安装软件的默认位置,otool的输出表示此Python的readline模块动态链接到安装了MacPorts的GNU读取库。
#2
15
If you are using homebrew, this is an easy fix:
如果您使用的是自制软件,这是一个简单的解决方法:
brew uninstall python brew uninstall readline brew install readline --universal brew install python
That fixed it for me (running OS X Mavericks 10.9.5)
为我修复它(运行OS X Mavericks 10.9.5)
#3
13
I finally got this working. I just had to install readline with easy_install and cursors and backspace started magically working.
我终于得到了这个工作。我只需要使用easy_install和游标安装readline,并且退格开始神奇地工作。
sudo /opt/local/bin/easy_install-2.5 readline
#4
5
This behaviour commonly shows when you do not have readline
support. If you are using MacPorts, try port install readline
, see if it will fix it. You can also see this page for some further explanations.
当您没有readline支持时,通常会显示此行为。如果您使用的是MacPorts,请尝试使用端口安装readline,看看它是否会修复它。您还可以查看此页面以获得进一步的解释。
(Also useful to know: some programs do not use readline
even if present on the system. You can force it on them by using rlwrap
(port install rlwrap
). For example: rlwrap ocaml -init code.ml
will start up OCaml, read code.ml, and start REPL with readline support)
(也很有用:一些程序即使存在于系统上也不使用readline。你可以使用rlwrap(port install rlwrap)强制它。例如:rlwrap ocaml -init code.ml将启动OCaml,读取code.ml,并启动REPL并支持readline)
#1
6
You don't say which Python you are using but the symptoms you mention are indeed usually caused by Python not being built with readline
support. These days Python on OS X can be built to use either the GNU readline
library or the Apple-supplied editline
library (AKA libedit
). You can use the following two commands to show exactly which Python you are using. If that does not help you figure out what is going on, edit your question to show the output from those commands.
你没有说你正在使用哪种Python,但你提到的症状确实通常是由于Python没有使用readline支持构建的。目前,OS X上的Python可以构建为使用GNU readline库或Apple提供的editline库(AKA libedit)。您可以使用以下两个命令准确显示您正在使用的Python。如果这无法帮助您弄清楚发生了什么,请编辑您的问题以显示这些命令的输出。
Here's an example that shows a recent MacPorts Python 2.6 on OS X 10.6:
这是一个示例,显示OS X 10.6上最近的MacPorts Python 2.6:
$ python -c 'import sys;print(sys.version);print(sys.executable)'
2.6.5 (r265:79063, Jul 15 2010, 01:53:46)
[GCC 4.2.1 (Apple Inc. build 5659)]
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
$ otool -L $(python -c 'import readline; print(readline.__file__)')
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/readline.so:
/opt/local/lib/libreadline.6.1.dylib (compatibility version 6.0.0, current version 6.1.0)
/opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
The path prefix /opt/local/
is the default location for MacPorts-installed software and the output from otool
indicates that this Python's readline
module is dynamically linked to the MacPorts-installed GNU readline
library.
路径前缀/ opt / local /是MacPorts安装软件的默认位置,otool的输出表示此Python的readline模块动态链接到安装了MacPorts的GNU读取库。
#2
15
If you are using homebrew, this is an easy fix:
如果您使用的是自制软件,这是一个简单的解决方法:
brew uninstall python brew uninstall readline brew install readline --universal brew install python
That fixed it for me (running OS X Mavericks 10.9.5)
为我修复它(运行OS X Mavericks 10.9.5)
#3
13
I finally got this working. I just had to install readline with easy_install and cursors and backspace started magically working.
我终于得到了这个工作。我只需要使用easy_install和游标安装readline,并且退格开始神奇地工作。
sudo /opt/local/bin/easy_install-2.5 readline
#4
5
This behaviour commonly shows when you do not have readline
support. If you are using MacPorts, try port install readline
, see if it will fix it. You can also see this page for some further explanations.
当您没有readline支持时,通常会显示此行为。如果您使用的是MacPorts,请尝试使用端口安装readline,看看它是否会修复它。您还可以查看此页面以获得进一步的解释。
(Also useful to know: some programs do not use readline
even if present on the system. You can force it on them by using rlwrap
(port install rlwrap
). For example: rlwrap ocaml -init code.ml
will start up OCaml, read code.ml, and start REPL with readline support)
(也很有用:一些程序即使存在于系统上也不使用readline。你可以使用rlwrap(port install rlwrap)强制它。例如:rlwrap ocaml -init code.ml将启动OCaml,读取code.ml,并启动REPL并支持readline)