Pythonインタラクティブシェルで方向キー入力が"[[A[[B[[C[[D"になる時の対処

意外に解決方法を知らない方がいる感じだったのでQiita投稿します。

#環境
 - Ubuntu
 - Python3.7
 
#方法

```
pip install gnureadline
```

#補足
以下のようなエラーが出る場合

```
Python 3.7.0 (default, Jan  7 2019, 20:01:26)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
*** Error in `python': free(): invalid pointer: 0x00007fd1158806a8 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fd114a6d7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fd114a7637a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fd114a7a53c]
python(PyOS_Readline+0xec)[0x599c4c]
python[0x59b910]
python[0x59d2f8]
python(PyTokenizer_Get+0x9)[0x59df19]
python[0x599dae]
python(PyParser_ASTFromFileObject+0xa3)[0x521cd3]
python[0x521f12]
python(PyRun_InteractiveLoopFlags+0x86)[0x522256]
python(PyRun_AnyFileExFlags+0x3c)[0x5223cc]
python[0x42de12]
python(_Py_UnixMain+0x7b)[0x42e72b]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fd114a16830]
python(_start+0x29)[0x429d59]
======= Memory map: ========
00400000-00690000 r-xp 00000000 fc:00 440806                             /home/frog/.pyenv/versions/3.7.0/bin/python3.7
0088f000-00890000 r--p 0028f000 fc:00 440806                             /home/frog/.pyenv/versions/3.7.0/bin/python3.7
00890000-008f9000 rw-p 00290000 fc:00 440806                             /home/frog/.pyenv/versions/3.7.0/bin/python3.7
008f9000-0091a000 rw-p 00000000 00:00 0
0254b000-0262f000 rw-p 00000000 00:00 0                                  [heap]
7fd10fdea000-7fd10fe00000 r-xp 00000000 fc:00 262294                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd10fe00000-7fd10ffff000 ---p 00016000 fc:00 262294                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd10ffff000-7fd110000000 rw-p 00015000 fc:00 262294                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd110000000-7fd110021000 rw-p 00000000 00:00 0
7fd110021000-7fd114000000 ---p 00000000 00:00 0
7fd114029000-7fd11404e000 r-xp 00000000 fc:00 262379                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fd11404e000-7fd11424d000 ---p 00025000 fc:00 262379                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fd11424d000-7fd114251000 r--p 00024000 fc:00 262379                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fd114251000-7fd114252000 rw-p 00028000 fc:00 262379                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fd114252000-7fd11428f000 r-xp 00000000 fc:00 439927                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/site-packages/readline.cpython-37m-x86_64-linux-gnu.so
7fd11428f000-7fd11448e000 ---p 0003d000 fc:00 439927                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/site-packages/readline.cpython-37m-x86_64-linux-gnu.so
7fd11448e000-7fd114490000 r--p 0003c000 fc:00 439927                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/site-packages/readline.cpython-37m-x86_64-linux-gnu.so
7fd114490000-7fd114497000 rw-p 0003e000 fc:00 439927                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/site-packages/readline.cpython-37m-x86_64-linux-gnu.so
7fd114497000-7fd1144d9000 rw-p 00000000 00:00 0
7fd1144d9000-7fd1144db000 r-xp 00000000 fc:00 444358                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/lib-dynload/_heapq.cpython-37m-x86_64-linux-gnu.so
7fd1144db000-7fd1146db000 ---p 00002000 fc:00 444358                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/lib-dynload/_heapq.cpython-37m-x86_64-linux-gnu.so
7fd1146db000-7fd1146dc000 r--p 00002000 fc:00 444358                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/lib-dynload/_heapq.cpython-37m-x86_64-linux-gnu.so
7fd1146dc000-7fd1146de000 rw-p 00003000 fc:00 444358                     /home/frog/.pyenv/versions/3.7.0/lib/python3.7/lib-dynload/_heapq.cpython-37m-x86_64-linux-gnu.so
7fd1146de000-7fd11471e000 rw-p 00000000 00:00 0
7fd11471e000-7fd1149f6000 r--p 00000000 fc:00 131972                     /usr/lib/locale/locale-archive
7fd1149f6000-7fd114bb6000 r-xp 00000000 fc:00 343997                     /lib/x86_64-linux-gnu/libc-2.23.so
7fd114bb6000-7fd114db6000 ---p 001c0000 fc:00 343997                     /lib/x86_64-linux-gnu/libc-2.23.so
7fd114db6000-7fd114dba000 r--p 001c0000 fc:00 343997                     /lib/x86_64-linux-gnu/libc-2.23.so
7fd114dba000-7fd114dbc000 rw-p 001c4000 fc:00 343997                     /lib/x86_64-linux-gnu/libc-2.23.so
7fd114dbc000-7fd114dc0000 rw-p 00000000 00:00 0
7fd114dc0000-7fd114ec8000 r-xp 00000000 fc:00 343993                     /lib/x86_64-linux-gnu/libm-2.23.so
7fd114ec8000-7fd1150c7000 ---p 00108000 fc:00 343993                     /lib/x86_64-linux-gnu/libm-2.23.so
7fd1150c7000-7fd1150c8000 r--p 00107000 fc:00 343993                     /lib/x86_64-linux-gnu/libm-2.23.so
7fd1150c8000-7fd1150c9000 rw-p 00108000 fc:00 343993                     /lib/x86_64-linux-gnu/libm-2.23.so
7fd1150c9000-7fd1150cb000 r-xp 00000000 fc:00 344004                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fd1150cb000-7fd1152ca000 ---p 00002000 fc:00 344004                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fd1152ca000-7fd1152cb000 r--p 00001000 fc:00 344004                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fd1152cb000-7fd1152cc000 rw-p 00002000 fc:00 344004                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fd1152cc000-7fd1152cf000 r-xp 00000000 fc:00 343999                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fd1152cf000-7fd1154ce000 ---p 00003000 fc:00 343999                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fd1154ce000-7fd1154cf000 r--p 00002000 fc:00 343999                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fd1154cf000-7fd1154d0000 rw-p 00003000 fc:00 343999                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fd1154d0000-7fd1154e8000 r-xp 00000000 fc:00 343996                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fd1154e8000-7fd1156e7000 ---p 00018000 fc:00 343996                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fd1156e7000-7fd1156e8000 r--p 00017000 fc:00 343996                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fd1156e8000-7fd1156e9000 rw-p 00018000 fc:00 343996                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fd1156e9000-7fd1156ed000 rw-p 00000000 00:00 0
7fd1156ed000-7fd115713000 r-xp 00000000 fc:00 343995                     /lib/x86_64-linux-gnu/ld-2.23.so
7fd115739000-7fd1158de000 rw-p 00000000 00:00 0
7fd1158de000-7fd115905000 r--p 00000000 fc:00 132902                     /usr/lib/locale/C.UTF-8/LC_CTYPE
7fd115905000-7fd11590b000 rw-p 00000000 00:00 0
7fd11590b000-7fd115912000 r--s 00000000 fc:00 223244                     /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
7fd115912000-7fd115913000 r--p 00025000 fc:00 343995                     /lib/x86_64-linux-gnu/ld-2.23.so
7fd115913000-7fd115914000 rw-p 00026000 fc:00 343995                     /lib/x86_64-linux-gnu/ld-2.23.so
7fd115914000-7fd115915000 rw-p 00000000 00:00 0
7ffe18f0d000-7ffe18f2e000 rw-p 00000000 00:00 0                          [stack]
7ffe18f9a000-7ffe18f9d000 r--p 00000000 00:00 0                          [vvar]
7ffe18f9d000-7ffe18f9f000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
```

恐らく``pip``にて``readline``がインストールされてるかと思われるので

```
pip uninstall readline
```

をして

```
pip install gnureadline
```

をする

#参考URL
[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)
[Python 3.6.1 crashed after I installed readline module](https://stackoverflow.com/questions/43013060/python-3-6-1-crashed-after-i-installed-readline-module)