nathancahill
nathancahill

Reputation: 10850

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

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=

Upvotes: 6

Views: 3074

Answers (2)

Eino Gourdin
Eino Gourdin

Reputation: 4507

libreadline-dev was not enough, what solved it for me is to install the readline package:

pip install readline

Upvotes: 1

Dietrich Epp
Dietrich Epp

Reputation: 213328

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.

Upvotes: 6

Related Questions