简体   繁体   中英

'python' command segmentation fault on raspberry pi

My problem is fairly simple: running the 'python' command (not a script) on my raspberry pi model A+ running Raspbian Wheezy gives a segmentation fault:

pi@raspberrypi ~ $ python
Segmentation fault

I found quite a number of threads dealing with 'segmentation fault' in python scripts (often related to 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 ).

But those are not answering my problem.

Running it in gdb gave:

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

I found this related post , but no clear solution is given.

Last element: python3 works just fine.

Would anyone here have an idea of what is happening?

Thanks for your help ~

The messages you're getting from GDB when running Python suggest the Python executable you're trying to use is for some reason corrupted. Try reinstalling all Python-related packages:

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

I had a similar problem where python3 was segfaulting, but apt could not install or remove packages because it invokes /usr/bin/apt-listchanges , a Python 3 script that couldn't execute.

At one point I received the message cannot open /var/lib/dpkg/info/parted.list (Structure needs cleaning) which suggested that there was some filesystem corruption. So if you encounter this issue, see if this is the case.

I created the /forcefsck file to force a filesystem repair on the next boot. The system didn't come back up—better have a serial cable and a spare SD card ready.

If it had come back up, I would have run apt install python3-dbg to download the GDB debugging extensions , even if apt would eventually crash — you could install manually with sudo dpkg -i /var/cache/apt/archives/python3.7-dbg*.deb .

I had a similar problem on a Raspberry Pi, in my case with Python2. Like @rgov and @icktoofay suggest I had a corrupted binary. gdb wouldn't even load the binary. After a forced fsck, sudo dpkg -i /var/cache/apt/python2.7* fixed this problem, and I was then able to do a sudo apt --fix-broken install . It's possible that my card is failing, or that low power quality is causing write failures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM