Cannot edit line in python command line on Linux

I am running the Python CLI under Linux:

bla:visualization> python
Python 2.1.1 (#18, Nov  1 2001, 11:15:13) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> 

For some reason, the arrow keys and the delete key do not work:

delete:

>>> x^H^H^H

up arrow:

>>> x^[[A^[[A

etc...

How can I do this work?

+3
source share
4 answers

The main problem is that your Python installation most likely was not compiled using the library readline. You can confirm this by trying to import the module readline:

import readline

You should get an import error if readlinenot.

If so, you can do nothing but recompile Python with the library readlineif you can.

+6

iPython (http://ipython.scipy.org/, easy_install pip), , CLI .

+3

Try to install the terminal from the shell stty. Pay special attention to special characters eraseand kill. Your Python installation is 8 years old; consider upgrading to a newer version.

+3
source

I had to install readline-devel to get this to work:

yum install readline-devel

Now my line editing commands in python work correctly.

0
source

Source: https://habr.com/ru/post/1714594/


All Articles