I installed python 3.8.6 on my centos 7 machine, compiling it with “./configure --enable-optimization” and “make altinstall”.
When I use python in terminal and I press the keyboard arrows or other buttons, instead of cursor movement, I obtain escape characters as ^[[A etc.
Can someone help me to avoid this behaviour on centos 7? many thanks
Best regards
My best guess would be that you’re missing readline. Try import readline - if that works, then you have a different problem ;-).
Python has many optional dependencies. My advice, if you want to build Python from source, would be to run configure again and carefully read the output. For every module it says is disabled and for every library it can’t find, try to figure out if you’re likely to need it and install the headers if necessary (yum install readline-devel or whatever)
Now, I used Scientific Linux 7 (which is basically CentOS 7) for a number of years and I found the most convenient ways to get a recent Python installed were either “Software Collections” (SCL) - though I don’t know if they have anything more recent than 3.6 - or Anaconda/Miniconda. Maybe either will work for you and save you from the hassle of compiling from source.
thank you for your reply. unfortunately when I try to install readline package, when I run python and I import a package the following error appears:
*** Error in `python3.8’: free(): invalid pointer: 0x00007fa348ef6bb0 ***
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f7f8d08bac5]
python3.8[0x40069e]
There are three things that you need to get this to work:
your OS needs readline; that is provided by default by Centos;
you also need the readline development libraries; that is not
provided by default;
you need to have readline support turned on in the Python build.
The readline module is not necessary for it, but it will be installed as
part of the standard library. You shouldn’t need to use pip to install
readline.
So you don’t need to do anything for #1 unless you are using some really
strange Linux setup. But if arrow keys work in the bash shell, then you
have readline installed.
Next you need the readline-devel package. You need to install that with
your distros’ package manager, which I think is yum. Try this:
yum install readline-devel
or maybe readline-dev.
Then you can build Python from source. As far as I know, by default
readline support is enabled, so you shouldn’t need to do anything to
turn it on.
If you build Python from source before installing readline-devel, it
won’t be able to link to the appropriate readline libraries and so it
won’t support arrow keys. Installing the readline module won’t fix that.
And installing readline with pip shouldn’t be necessary. It should be
included in the stdlib of the interpreter you build.