How do I repeat the last command? The usual keys: Up, Ctrl+Up, Alt-p don't work. They produce nonsensical characters.
(ve)[kakarukeys@localhost ve]$ python
Python 2.6.6 (r266:84292, Nov 15 2010, 21:48:32)
[GCC 4.4.4 20100630 (Red Hat 4.4.4-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world"
hello world
>>> ^[[A
File "<stdin>", line 1
^
SyntaxError: invalid syntax
>>> ^[[1;5A
File "<stdin>", line 1
[1;5A
^
SyntaxError: invalid syntax
>>> ^[p
File "<stdin>", line 1
p
^
SyntaxError: invalid syntax
>>>
look under
history-previous
for the command, you can change it to something you like better once here.I don't understand why there are so many long explanations about this. All you have to do is install the pyreadline package with:
sudo port install py-readline (on Mac)
(Assuming you have already installed PIP.)
On CentOS, I fix this by
and then recompile python 3.4.
On OpenSUSE, I fix this by
Referring to this answer:https://stackoverflow.com/a/26356378/2817654. Perhaps "pip3 install readline" is a general solution. Haven't tried on my CentOS.
I find information that I copied below answer the question
source
On Ubuntu 16.04, I had the same problem after upgrading Python from the preloaded 3.5 to version 3.7 from source code. As @erewok suggested, I did
followed by:
sudo make install
After that, the arrow-up key worked. Not sure which module is required to fix the problem or both, but without "make install", none would work. During initial make, there were some red-flag errors, but ignored and completed the build. This time, there didn't seem to have any errors.On Ubuntu Server 12.04, I had this problem after installing a version of Python from source (Python3.4).
Some of the comments here recommend installing Ipython and I want to mention that I have the same behavior even with Ipython. From what I can tell, this is a readline problem.
For Ubuntu 12.04 server, I had to install
libncurses-dev
andlibreadline-dev
and then install Python from source for up-history (readline) behavior to be enabled. I pretty much did this:After that, I deleted the previously installed Python (NOT THE SYSTEM PYTHON, the one I had installed from source!) and reinstalled it from source and everything worked as expected.
I did not have to install anything with pip or edit .pythonstartup.