'python' raspberry pi 上的命令分段错误

'python' command segmentation fault on raspberry pi

我的问题相当简单:运行 'python' 命令(不是脚本)在我的 raspberry pi 模型 A+ 运行 Raspbian Wheezy 给出了分段错误:

pi@raspberrypi ~ $ python
Segmentation fault

我在 python 脚本中发现了很多处理 'segmentation fault' 的线程(通常与 external C modules). Some others more specifically on raspberry pi were often speaking of 'segmentation fault' during an apt-get upgrade, involving a python module (here or there 相关)。

但这些并没有解决我的问题。

运行 它在 gdb 中给出:

pi@raspberrypi ~ $ gdb python
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python...BFD: /usr/bin/python: invalid string offset 4204450 >= 26547 for section `.dynstr'
BFD: /usr/bin/python: invalid string offset 34425 >= 26547 for section `.dynstr'
BFD: /usr/bin/python: invalid string offset 276647 >= 26547 for section `.dynstr'
...
(50 or so such lines later)
...
BFD: /usr/bin/python: invalid string offset 2340624285 >= 26547 for section `.dynstr'
(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python 

Program received signal SIGSEGV, Segmentation fault.
0xb6ff0124 in ?? () from /lib/ld-linux-armhf.so.3
(gdb) backtrace
#0  0xb6ff0124 in ?? () from /lib/ld-linux-armhf.so.3
#1  0xbefff358 in ?? ()
Cannot access memory at address 0x7a626964

找到了this related post,但是没有给出明确的解决方案

最后一个元素:python3 工作得很好。

这里有人知道发生了什么事吗?

感谢您的帮助~

当 运行 Python 表明您尝试使用的 Python 可执行文件由于某种原因已损坏时,您从 GDB 获得的消息。尝试重新安装所有 Python 相关的软件包:

$ sudo apt-get install --reinstall `dpkg --get-selections | grep -E '^(lib)?python' | cut -f1 | cut -d: -f1`

我有一个类似的问题,其中 python3 出现段错误,但是 apt 无法安装或删除软件包,因为它调用了 /usr/bin/apt-listchanges,一个 Python 3 脚本无法'执行。

有一次我收到消息 cannot open /var/lib/dpkg/info/parted.list (Structure needs cleaning),提示存在文件系统损坏。所以如果你遇到这个问题,看看是不是这种情况。

我创建了 /forcefsck 文件以在下次启动时强制修复文件系统。系统没有恢复——最好准备好串行电缆和备用 SD 卡。

如果它恢复了,我会 运行 apt install python3-dbg 下载 GDB debugging extensions,即使 apt 最终会崩溃 — 你可以手动安装sudo dpkg -i /var/cache/apt/archives/python3.7-dbg*.deb.

我在 Raspberry Pi 上遇到了类似的问题,在我的情况下 Python2。就像@rgov 和@icktoofay 暗示我有一个损坏的二进制文件。 gdb 甚至不会加载二进制文件。在强制 fsck 之后,sudo dpkg -i /var/cache/apt/python2.7* 解决了这个问题,然后我可以执行 sudo apt --fix-broken install。可能是我的卡坏了,或者电源质量低导致写入失败。