Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

^[[A and ^[[B show up in python interpreter when I press arrow keys

Tags:

python

ipython

What's going on? I tried iPython and the regular Python interpreter, both show ^[[A and ^[[B for the up and down arrows instead of previous commands.

Platform: Ubuntu 12.04.

Python: 2.7.3 installed with pythonbrew

Terminal: iTerm 2 on Mac OSX 10.6, connected over SSH.

Has never worked in the Python shell over SSH, but works locally.

Running locale outputs:

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
like image 571
nathancahill Avatar asked Jun 14 '12 06:06

nathancahill


1 Answers

Since you installed Python with pythonbrew, you must install the libreadline-dev package in your package manager then recompile Python.

The package is named libreadline-dev or something similar in most Linux distributions (Ubuntu, Debian, Fedora...). This step is not required on Gentoo or Arch systems, which always include dev support for libraries.

This step is also not necessary for Python that you install from the package manager.

Footnote: The locale is irrelevant. The terminal emulator is irrelevant. SSH is irrelevant. I have never seen these factors affect line editing capabilities, although I suppose anything's possible.

Footnote 2: I'm going to submit a patch to the docs for pythonbrew, this is not the first time someone has complained about readline missing. Update: Pull request Update 2: Merged.

like image 68
Dietrich Epp Avatar answered Sep 23 '22 00:09

Dietrich Epp