Python 3.5+ Arrow keys and others in the console

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Sun Apr 16 09:19:52 EDT 2017


On 16.04.2017 10:56, Vincent Vande Vyvre wrote:
> Hi,
>
> I'm using Python 3.5 and 3.6 in venv and I see a strange behaviour in
> the interactive interpreter.
>
> The arrow keys can't be used to move the cursor into the current line of
> code or to rewrite the last lines.
>
> With the 3.5 I can use the backspace and erase the code but not in 3.6
>
> Python 3.5.2 (default, Dec 19 2016, 11:46:33)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> f = "kjhfgt"^[[D            # Left Arrow Key
>>>> ^[[A                        # Up Arrow Key
>
>
> Python 3.6.1 (default, Apr 12 2017, 11:39:17)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> f = "lkjgh"
>>>> ^[[A^[[B                    # Up Arrow Key and Backspace Key
>   File "<stdin>", line 1
>
>     ^
> SyntaxError: invalid syntax
>>>>
>

Make sure you build Python (I guess you did this for 3.6, but are 
probably using your OS Python3.5) with readline. This needs the dev 
version of the readline library installed at build time.
So, step 1 would be to get the library, then rebuild Python3.6 by running:

1) make clean
2) ./configure
3) make

It could be worthwhile checking for other missing optional C libraries 
first though. If you want to make sure you have all of them, follow the 
steps described here:

https://docs.python.org/devguide/setup.html#build-dependencies

Best,
Wolfgang





More information about the Python-list mailing list