arrow keys not working in python interpreter

10,260

Solution 1

As you said in comments, fixing the command to install the libreadline-dev package as suggested by the post on SO you linked seems to have solved your problem.

Here is the correct command again:

sudo apt install libreadline-dev

Solution 2

I believe this question has been addressed on SO. Aside from libreadline-dev, you may need to run sudo pip install readline

https://stackoverflow.com/questions/893053/seeing-escape-characters-when-pressing-the-arrow-keys-in-python-shell

Share:
10,260

Related videos on Youtube

Malik A. Rumi
Author by

Malik A. Rumi

Updated on September 18, 2022

Comments

  • Malik A. Rumi
    Malik A. Rumi over 1 year

    I am using Python 3.6.2 on Ubuntu 16.04. On all prior versions of Python, I have never had this issue. I have googled around. There is no post on AskUbuntu on this specific issue that I could find. There is one on SO, but it is pretty old. I don't have etc/pythonstart as the accepted answer suggests and this is the ONLY place I've found that even references such a thing.

    This SO answer is also old, but when I tried the solution:

    malikarumi@Tetuoan2:~$ apt-get libreadline-dev
    E: Invalid operation libreadline-dev
    malikarumi@Tetuoan2:~$ sudo apt-get libreadline-dev
    [sudo] password for malikarumi: 
    E: Invalid operation libreadline-dev
    malikarumi@Tetuoan2:~$ apt-get libreadline
    E: Invalid operation libreadline
    malikarumi@Tetuoan2:~$ sudo apt-get libreadline
    E: Invalid operation libreadline
    malikarumi@Tetuoan2:~$ apt-get readline
    E: Invalid operation readline
    malikarumi@Tetuoan2:~$ sudo apt-get readline
    E: Invalid operation readline
    

    I do have the GNU Readline Library, up to 6, in usr/share/doc, so I don't know why that's not working for me since, as I said, I never had this issue on <3.6

    So since this seems more like a OS issue than a Python one, I decided to post here. Suggestions? And let me know if the rebuild is still necessary. Thanks.

    • Byte Commander
      Byte Commander over 6 years
      Where do you have Python 3.6 from/how did you install it? The version from Ubuntu's repositories for 16.04 is 3.5 only. Also the command you seem to have tries would need to be sudo apt install libreadline-dev, but the answer mentioned this only changes anything if you compile the Python interpreter from source.
    • Malik A. Rumi
      Malik A. Rumi over 6 years
      @ByteCommander right, that's why I was asking if the rebuild from source suggestion still applies. I got this from python.org. And you're right, sudo apt-get install works. Thanks. Do you want to make this an answer so I can accept it?
  • int_ua
    int_ua about 3 years
    The description of the package says that Ubuntu should already use proper readline and you shouldn't have to install it pypi.org/project/gnureadline What Ubuntu version are you using?