3

I am using ubuntu, linux kernel 2.6.38. I usually use python2, today, I decide to try Python3. I downloads python3 and make install it following the README. However,the python 3.2 interpreter can not recognize UP/SOWN/LEFT/RIGHT keys, these keys are available in my python 2.7 interpreter. What's wrong did I make?

enter image description here

Another question is can I choose the python version which iPython use if I have python2.7 and python3.2 at the same time.

Best Regards.

hakunami
  • 2,351
  • 4
  • 31
  • 50
  • Does this answer your question? [Seeing escape characters when pressing the arrow keys in python shell](https://stackoverflow.com/questions/893053/seeing-escape-characters-when-pressing-the-arrow-keys-in-python-shell) – He3lixxx Aug 31 '23 at 13:56

2 Answers2

7

This happens if the GNU Readline Library is not installed. Install the development version of the Readline library and recompile. (Some Linux distros have different packages for the development version and the runtime version of a library. The development version is needed to compile packages which use the library.)

On Debian-derived distros like Ubuntu, the package is libreadline-dev.

sudo apt install libreadline-dev

On Redhat-derived distros like Fedora, the package is named readline-devel.

sudo dnf install readline-devel

You may be able to use the Editline library instead of Readline. It’s basically a different library that does the same thing.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
  • Sorry, I don't know how to recompile. You mean I should do the install instructions in README again? – hakunami May 26 '12 at 10:31
  • Yes, start again from the beginning. That will recompile Python. – Dietrich Epp May 26 '12 at 10:35
  • Uninstalling is not necessary, neither is `make clean`. – Dietrich Epp May 26 '12 at 10:49
  • It seems unlikely that he needs to compile Python from scratch, so installing the `python3` package is a much simpler option. – Thomas K May 26 '12 at 11:21
  • @ThomasK: The asker already downloaded, compiled, and installed Python, so installing `readline-dev` isn't much of an additional bother. Also, installing the `python3` package would probably not work without first uninstalling since `/usr/local` usually comes first in `$PATH`. – Dietrich Epp May 26 '12 at 13:35
  • If someone has this issue on Redhat, and finds their way here (to StackOverflow) here is the command they need to run: yum install readline-devel – PyTis Jan 30 '23 at 16:29
6

This happens when compiling python without readline support. Install the readline developement pakckages so that the readline.so module gets build when compiling.

If you want to use ipython on both python2 and python3, you'll have to install it separately for each interpreter.

One last hint: the ubuntu already has python3 in it's repository. you can install it using:

sudo apt-get install python3 ipython3
mata
  • 67,110
  • 10
  • 163
  • 162
  • No, it should not be preinstalled. And the last Ubuntu release also has Linux 3.2, not Linux 2.6 mentioned in the OP. But who cares, the information about the Linux version is totally irrelevant anyway. ;-) – Gandaro May 26 '12 at 10:40
  • yea, you're right, that's only true for ubuntu 12.4, i didn't really look at the version. – mata May 26 '12 at 10:54
  • then i probably have interpreted [this](https://wiki.ubuntu.com/PrecisePangolin/ReleaseNotes/UbuntuDesktop#PrecisePangolin.2BAC8-ReleaseNotes.2BAC8-CommonInfrastructure.Python_Toolchain) wrong... – mata May 26 '12 at 11:20
  • +1 for suggesting installing the packages - that's much easier than compiling Python. – Thomas K May 26 '12 at 11:22
  • @mata Yes, you did. It means, that you can install Python 3.2.3 via apt out of the box. -.- – Gandaro May 29 '12 at 11:32