Seeing escape characters when pressing the arrow keys in python shell

Frank picture Frank · May 21, 2009 · Viewed 70.3k times · Source

In shells like the interactive python shell, you can usually use the arrow keys to move around in the current line or get previous commands (with arrow-up) etc.

But after I ssh into another machine and start python there, I get sessions like:

>>> import os 
>>> ^[[A    

where the last character comes from arrow-up. Or, using arrow-left:

>>> impor^[[D

How can I fix this?

In the regular bash, arrow keys work fine. The weird behavior is just in the interactive python (or perl etc.) shell.

Answer

Valerio Crini picture Valerio Crini · Oct 14, 2014

I've solved this issue by installing readline package:

pip install readline