Nathan Fellman
Nathan Fellman

Reputation: 127588

can't edit line in python's command line in Linux

I'm 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 don't work:

delete:

>>> x^H^H^H

up arrow:

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

etc...

How can I make these work?

Upvotes: 3

Views: 613

Answers (4)

Tom Ekberg
Tom Ekberg

Reputation: 2271

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

yum install readline-devel

Now my python command line editing keystrokes work properly.

Upvotes: 0

Pinochle
Pinochle

Reputation: 5563

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

import readline

You should get an error when you import if readline is not present.

If this is the case, there's not much you can do other than recompile Python with the readline library, if you can.

Upvotes: 6

gimel
gimel

Reputation: 86482

Try setting your terminal from the shell, with stty. Pay special attention to the special characters erase and kill. Your Python installation is 8 years old, consider updating to a newer version.

Upvotes: 3

juanjux
juanjux

Reputation: 641

Install iPython ( http://ipython.scipy.org/ but can be installed using easy_install or pip), it is much much better than the default CLI.

Upvotes: 3

Related Questions