How come when I press the Up or Down Arrow keys in the Python interpreter I get ^[[A or ^[[B instead of history?

user883807 picture user883807 · Dec 13, 2011 · Viewed 12.6k times · Source

Possible Duplicate:
Python shell: Arrow keys do not work on remote machine

I have no idea why history won't work in the Python 2.7.2 interpreter. I get strange character groups for each of the arrow keys. This doesn't happen in Terminal. BTW I am on Ubuntu 10.04. Here is a screen shot of this hell:

enter image description here

How do I get back the ability to get my command history by pressing the Up and Down Arrow keys?

Answer

Vinay Sajip picture Vinay Sajip · Dec 13, 2011

It looks as if you're using a build from source. It looks like you'll need to rebuild Python after installing the libreadline-dev or equivalent package on your distribution.

Update: There should be no special build steps needed, just running make should do. There are some messages printed at the end about optional modules which couldn't be built because of missing dependencies (in addition to readline, there are also Tcl/Tk, zlib, gdbm and openssl dependencies, for example).

If for some reason just running make doesn't work, try running configure again first (if make doesn't already run it for you).