安装 readline 模块后 Python 3.6.1 崩溃

Posted

技术标签:

【中文标题】安装 readline 模块后 Python 3.6.1 崩溃【英文标题】:Python 3.6.1 crashed after readline module installed 【发布时间】:2017-08-18 04:36:54 【问题描述】:

我已经从源代码编译并安装了 Python 3.6.1,并运行 sudo pip3 install readline 来安装 readline 模块。但是当我启动 Python shell 时,无论我输入什么,它都会崩溃:

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)

这是怎么回事?我使用的是 Ubuntu 16.04。

【问题讨论】:

【参考方案1】:

苹果机:

pip install readline

窗户:

pip install pyreadline

Unix:

pip install gnureadline

【讨论】:

【参考方案2】:

改用pip install gnureadline。并删除 readline:pip uninstall readline

正如 pypi.org 上的 gnureadline package page 所解释的:

某些平台,例如 macOS,没有安装 GNU readline

此模块 [捆绑] 标准 Python readline 模块与 GNU readline 源代码,编译并静态链接到它。最终结果是一个易于安装且不需要额外共享库的包。

所以gnureadline 包附带编译和链接所需的代码,而builtin python readline library 依赖于已安装在系统上的 GNU readline(或替代方案)。

【讨论】:

这非常有用。谢谢! 解决了Python3.6.4中同样的问题。 适用于 Ubuntu 18.04 上的 Python 3.7.3 适用于 Ubuntu 16.04 上的 Python 3.7.0。谢谢! 适用于 Ubuntu 18.04 上的 Python 3.7.4【参考方案3】:

据我所知,这与下面遇到的相同问题。我已经在那里发布了对我有用的答案。

python 3.6 crash after install readline

【讨论】:

【参考方案4】:

同样的问题。 使用gcc-4.7编译python源码解决gcc-5.4

【讨论】:

以上是关于安装 readline 模块后 Python 3.6.1 崩溃的主要内容,如果未能解决你的问题,请参考以下文章

Redhat安装python环境(readline模块)

linux系统安装python2.7

python - readline 模块

那些奇葩python模块怎么交叉编译呀

python Python模块urllib:readlines函数

python shell 方向键不可用