28

Possible Duplicate:
Python shell: Arrow keys do not work on remote machine

I have no idea why history won't work in the Python 2.7.2 interpreter. I get strange character groups for each of the arrow keys. This doesn't happen in Terminal. BTW I am on Ubuntu 10.04. Here is a screen shot of this hell:

enter image description here

How do I get back the ability to get my command history by pressing the Up and Down Arrow keys?

Community
  • 1
  • 1
  • The following might be of some help: http://stackoverflow.com/questions/893053/python-shell-arrow-keys-do-not-work-on-remote-machine – NPE Dec 13 '11 at 20:25
  • What is the value of your `$TERM` environment variable? How are you invoking the Python interpreter? Are you typing `python` from a shell prompt? If so, what terminal emulator is the shell running under? – Keith Thompson Dec 13 '11 at 20:28
  • You don't need to install any of the optional components - Python will build without them. If you need any of them, get the latest ones from your distro. – Vinay Sajip Dec 14 '11 at 13:15
  • @KeithThompson I am using Gnome Terminal. Running `echo $TERM` prints out `xterm-256color`. I invoke Python interpreter by typing `python`. @VinaySajip Ok thanks. –  Dec 19 '11 at 09:42

1 Answers1

26

It looks as if you're using a build from source. It looks like you'll need to rebuild Python after installing the libreadline-dev or equivalent package on your distribution.

Update: There should be no special build steps needed, just running make should do. There are some messages printed at the end about optional modules which couldn't be built because of missing dependencies (in addition to readline, there are also Tcl/Tk, zlib, gdbm and openssl dependencies, for example).

If for some reason just running make doesn't work, try running configure again first (if make doesn't already run it for you).

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
  • Thanks. I just installed `libreadline-dev`. Now how should I go about rebuilding Python 2.7.2? Any specific steps I should take in the rebuilding process? –  Dec 13 '11 at 21:14
  • what versions of `tcl`, `tk`, and `zlib` should I install? –  Dec 13 '11 at 23:36
  • I recompiled Python 2.7.2 after installing `libreadline-dev` and all is in working order. Up and Down arrow keys change the command history as expected. –  Dec 19 '11 at 12:45
  • @vinay-sajip I am in this situation 6 years later. I have libreadline now, but am I supposed to remove the current 3.6 I have? Do I run make from the directory where the current 3.6 executable is? I'm just not sure what the right steps are. Hope you can help. Thanks. – Malik A. Rumi Oct 03 '17 at 21:46
  • @MalikA.Rumi This is really a separate question about how to build Python from source. Consult the official documentation. – Vinay Sajip Oct 04 '17 at 09:04