Python 3.6.1 crashed after readline module installed

Question:

I’ve compiled and installed Python 3.6.1 from source code, and run sudo pip3 install readline to install the readline module. But when I start the Python shell, it crashes whatever I enter:

Python 3.6.1 (default, Mar 25 2017, 13:40:56) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello")
*** Error in `python3': munmap_chunk(): invalid pointer: 0x00007fa3c64960a0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fa3c565e7e5]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x1a8)[0x7fa3c566aae8]
python3(PyOS_Readline+0xec)[0x5c3bcc]
python3[0x447cd0]
python3[0x449788]
python3(PyTokenizer_Get+0x9)[0x44a659]
python3[0x44617e]
python3(PyParser_ASTFromFileObject+0xa3)[0x428803]
python3(PyRun_InteractiveOneObject+0x122)[0x428a42]
python3(PyRun_InteractiveLoopFlags+0x6e)[0x428dce]
python3(PyRun_AnyFileExFlags+0x3c)[0x428efc]
python3(Py_Main+0xe4f)[0x43ba3f]
python3(main+0x162)[0x41dc52]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fa3c5607830]
python3(_start+0x29)[0x41dd29]
======= Memory map: ========
00400000-00663000 r-xp 00000000 08:05 16779642                           /usr/local/bin/python3.6
00862000-00863000 r--p 00262000 08:05 16779642                           /usr/local/bin/python3.6
00863000-008c7000 rw-p 00263000 08:05 16779642                           /usr/local/bin/python3.6
008c7000-008f7000 rw-p 00000000 00:00 0 
00d60000-00e31000 rw-p 00000000 00:00 0                                  [heap]
7fa3c4a96000-7fa3c4aac000 r-xp 00000000 08:05 528788                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3c4aac000-7fa3c4cab000 ---p 00016000 08:05 528788                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3c4cab000-7fa3c4cac000 rw-p 00015000 08:05 528788                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3c4cac000-7fa3c4cec000 rw-p 00000000 00:00 0 
7fa3c4cec000-7fa3c4d11000 r-xp 00000000 08:05 528922                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fa3c4d11000-7fa3c4f10000 ---p 00025000 08:05 528922                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fa3c4f10000-7fa3c4f14000 r--p 00024000 08:05 528922                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fa3c4f14000-7fa3c4f15000 rw-p 00028000 08:05 528922                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7fa3c4f15000-7fa3c4f52000 r-xp 00000000 08:05 16786336                   /usr/local/lib/python3.6/site-packages/readline.cpython-36m-x86_64-linux-gnu.so
7fa3c4f52000-7fa3c5151000 ---p 0003d000 08:05 16786336                   /usr/local/lib/python3.6/site-packages/readline.cpython-36m-x86_64-linux-gnu.so
7fa3c5151000-7fa3c5153000 r--p 0003c000 08:05 16786336                   /usr/local/lib/python3.6/site-packages/readline.cpython-36m-x86_64-linux-gnu.so
7fa3c5153000-7fa3c515a000 rw-p 0003e000 08:05 16786336                   /usr/local/lib/python3.6/site-packages/readline.cpython-36m-x86_64-linux-gnu.so
7fa3c515a000-7fa3c515c000 rw-p 00000000 00:00 0 
7fa3c515c000-7fa3c55e7000 r--p 00000000 08:05 16253117                   /usr/lib/locale/locale-archive
7fa3c55e7000-7fa3c57a6000 r-xp 00000000 08:05 524633                     /lib/x86_64-linux-gnu/libc-2.23.so
7fa3c57a6000-7fa3c59a6000 ---p 001bf000 08:05 524633                     /lib/x86_64-linux-gnu/libc-2.23.so
7fa3c59a6000-7fa3c59aa000 r--p 001bf000 08:05 524633                     /lib/x86_64-linux-gnu/libc-2.23.so
7fa3c59aa000-7fa3c59ac000 rw-p 001c3000 08:05 524633                     /lib/x86_64-linux-gnu/libc-2.23.so
7fa3c59ac000-7fa3c59b0000 rw-p 00000000 00:00 0 
7fa3c59b0000-7fa3c5ab8000 r-xp 00000000 08:05 524562                     /lib/x86_64-linux-gnu/libm-2.23.so
7fa3c5ab8000-7fa3c5cb7000 ---p 00108000 08:05 524562                     /lib/x86_64-linux-gnu/libm-2.23.so
7fa3c5cb7000-7fa3c5cb8000 r--p 00107000 08:05 524562                     /lib/x86_64-linux-gnu/libm-2.23.so
7fa3c5cb8000-7fa3c5cb9000 rw-p 00108000 08:05 524562                     /lib/x86_64-linux-gnu/libm-2.23.so
7fa3c5cb9000-7fa3c5cbb000 r-xp 00000000 08:05 524647                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fa3c5cbb000-7fa3c5eba000 ---p 00002000 08:05 524647                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fa3c5eba000-7fa3c5ebb000 r--p 00001000 08:05 524647                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fa3c5ebb000-7fa3c5ebc000 rw-p 00002000 08:05 524647                     /lib/x86_64-linux-gnu/libutil-2.23.so
7fa3c5ebc000-7fa3c5ebf000 r-xp 00000000 08:05 524547                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fa3c5ebf000-7fa3c60be000 ---p 00003000 08:05 524547                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fa3c60be000-7fa3c60bf000 r--p 00002000 08:05 524547                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fa3c60bf000-7fa3c60c0000 rw-p 00003000 08:05 524547                     /lib/x86_64-linux-gnu/libdl-2.23.so
7fa3c60c0000-7fa3c60d8000 r-xp 00000000 08:05 524644                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fa3c60d8000-7fa3c62d7000 ---p 00018000 08:05 524644                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fa3c62d7000-7fa3c62d8000 r--p 00017000 08:05 524644                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fa3c62d8000-7fa3c62d9000 rw-p 00018000 08:05 524644                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7fa3c62d9000-7fa3c62dd000 rw-p 00000000 00:00 0 
7fa3c62dd000-7fa3c6303000 r-xp 00000000 08:05 524634                     /lib/x86_64-linux-gnu/ld-2.23.so
7fa3c6339000-7fa3c64e2000 rw-p 00000000 00:00 0 
7fa3c64f8000-7fa3c64f9000 rw-p 00000000 00:00 0 
7fa3c64f9000-7fa3c6500000 r--s 00000000 08:05 16522416                   /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
7fa3c6500000-7fa3c6502000 rw-p 00000000 00:00 0 
7fa3c6502000-7fa3c6503000 r--p 00025000 08:05 524634                     /lib/x86_64-linux-gnu/ld-2.23.so
7fa3c6503000-7fa3c6504000 rw-p 00026000 08:05 524634                     /lib/x86_64-linux-gnu/ld-2.23.so
7fa3c6504000-7fa3c6505000 rw-p 00000000 00:00 0 
7ffcb1700000-7ffcb1721000 rw-p 00000000 00:00 0                          [stack]
7ffcb17ad000-7ffcb17af000 r--p 00000000 00:00 0                          [vvar]
7ffcb17af000-7ffcb17b1000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

What’s the matter here? I’m using Ubuntu 16.04.

Asked By: hsfzxjy

||

Answers:

Same problem.
Solve it by using gcc-4.7 for compilation python source instead gcc-5.4

Answered By: Alex Qel

As far as I can tell, this is the same problem encountered below. I’ve posted the answer that worked for me, there.

python 3.6 crash after install readline

Answered By: krieghan

Try pip install gnureadline instead. And remove readline: pip uninstall readline.

As explained by the gnureadline package page on pypi.org:

Some platforms, such as macOS, do not ship with GNU readline installed

This module [bundles] the standard Python readline module with the GNU readline source code, which is compiled and statically linked to it. The end result is a package which is simple to install and requires no extra shared libraries.

So the gnureadline package comes with the required code compiled and linked whereas the builtin python readline library relies on GNU readline (or an alternative) to be installed on the system already.

Answered By: Coykto

Mac:

pip install readline

Windows:

pip install pyreadline

Unix:

pip install gnureadline
Answered By: Olshansk
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.