请问Raspbian 11 上 Python 本身出错无法运行怎么办?

Teklimakan 50cm2024-05-25355 次点击
连带着 `apt upgrade` 也不能用了,具体如下:
```
┌──(pi@raspberrypi)-[~]
└─$ python
zsh: segmentation fault python

┌──(pi@raspberrypi)-[~]
└─$ sudo apt upgrade -y
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
正在计算更新... 完成
下列软件包将被升级:
ghostscript less libglib2.0-0 libgs9 libgs9-common
升级了 5 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 0 B/4,030 kB 的归档。
解压缩后会消耗 17.4 kB 的额外空间。
Segmentation fault
E: 子进程 /usr/bin/apt-listchanges --apt || test $? -lt 10 返回了一个错误号 (1)
E: Failure running script /usr/bin/apt-listchanges --apt || test $? -lt 10
```

系统情况:
```
┌──(pi@raspberrypi)-[~]
└─$ uname -a
Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l GNU/Linux

┌──(pi@raspberrypi)-[~]
└─$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
```

我没有卸载 python:
```
┌──(pi@raspberrypi)-[~]
└─$ ll /usr/bin/python*
lrwxrwxrwx 7 root root 3 3月 2021 /usr/bin/python -> python3
lrwxrwxrwx 9 root root 5 4月 2021 /usr/bin/python3 -> python3.9
lrwxrwxrwx 16 root root 5 4月 2021 /usr/bin/python3-config -> python3.9-config
.rwxr-xr-x 6.4k root root 27 7月 2020 /usr/bin/python3-wsdump
.rwxr-xr-x 4.7M root root 12 3月 2021 /usr/bin/python3.9
lrwxrwxrwx 36 root root 12 3月 2021 /usr/bin/python3.9-config -> arm-linux-gnueabihf-python3.9-config

┌──(pi@raspberrypi)-[~]
└─$ ll /bin/python*
lrwxrwxrwx 7 root root 3 3月 2021 /bin/python -> python3
lrwxrwxrwx 9 root root 5 4月 2021 /bin/python3 -> python3.9
lrwxrwxrwx 16 root root 5 4月 2021 /bin/python3-config -> python3.9-config
.rwxr-xr-x 6.4k root root 27 7月 2020 /bin/python3-wsdump
.rwxr-xr-x 4.7M root root 12 3月 2021 /bin/python3.9
lrwxrwxrwx 36 root root 12 3月 2021 /bin/python3.9-config -> arm-linux-gnueabihf-python3.9-config

┌──(pi@raspberrypi)-[~]
└─$ which python
/usr/bin/python
```
翻遍了,有 `apt-list` 报错的解决办法,但对我都不管用。之后我偶然运行一个 python 脚本,发现无法运行,然后发现就像最上面那样 python 本身都无法运行了,所以就推断应该是 `apt-list` 需要用到 python,但是我的系统上 python 却坏了,这才导致 `apt-upgrade` 不能运行。目前发现 `apt` 系列命令里只有 `apt update` 可以运行,`remove`、`install`、`upgrade` 等等都报错,不能运行。机器是树莓派2B,其他软件 nginx、php-myadmin 等都正常运行。

写到这我想起来最近唯一一次异常行为,是在一次意外断电后,后台占用一直很高,ssh都卡的不行,排查发现是 mariadb 不知道为啥一直在占资源却启动不起来,我不怎么用她,于是就 mask 掉了,现在 unmask 试一下,不过基本上也还是重现之前的卡死而已吧……
收藏 ♥ 感谢
Spoony 小组长 2024-05-26 
手动重新安装 python 试试
Teklimakan 50cm 2024-05-31  ♥ 1
@Spoony 就……不知道怎么手动重新安装 python,所以在另一张卡上重装了系统,复制了 `home` 和 `etc` 目录下的一些配置文件,目前是解决了。就是用着用着碰到忘了复制过来的配置文件,把原来的系统卡直接插上,然后挂载在 `mnt` 里面不会有问题吧?
Spoony 小组长 2024-06-02 
@Teklimakan 可以的

登录注册 后可回复。