Ubuntu 20.04 上的 python3 损坏了,我无法修复它

Ubuntu 20.04 上的 python3 损坏了,我无法修复它

我不知怎么搞乱了 Ubuntu 20.04(从 19.10 升级)中的 python3 环境。我不知道这到底是怎么发生的,但重新启动后,我无法再启动 gnome 终端。请注意,自从大约 2 周前升级以来,到目前为止,它一直运行良好。

我怀疑这可能是由于chmodsudo在重启笔记本电脑之前的会话中运行了一个错误的命令。但我不能 100% 确定,因为我chmod在软件项目的文件夹中运行了该命令(以修复权限),而且我真的必须弄乱命令才能造成这种损害。

现在我无法安装 python3 来修复系统,也无法在系统上更新/重新安装(可能修复 python3 包的权限),因为一切都依赖于 python3。

以下是我迄今为止尝试过的:

从 XTerm 启动 gnome-terminal 时出现此错误:

root@ierbert2:/home/micha# gnome-terminal
bash: /usr/bin/gnome-terminal: /usr/bin/python3: bad interpreter: Permission denied

ll /usr/bin/python*返回:

root@/****:/home/****# ll /usr/bin/python*
lrwxrwxrwx 1 root root       7 Apr 15 12:45 /usr/bin/python -> python2*
lrwxrwxrwx 1 root root       9 Mär 13 13:31 /usr/bin/python2 -> python2.7*
-rwxr-xr-x 1 root root 3694632 Apr  7 14:05 /usr/bin/python2.7*
lrwxrwxrwx 1 root root       9 Mär 13 13:20 /usr/bin/python3 -> python3.8
-rw-rw-r-- 1 root root 5457536 Apr 27 17:53 /usr/bin/python3.8
lrwxrwxrwx 1 root root      33 Apr 27 17:53 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config*
lrwxrwxrwx 1 root root      16 Mär 13 13:20 /usr/bin/python3-config -> python3.8-config*
-rwxr-xr-x 1 root root     384 Mär 28 03:39 /usr/bin/python3-futurize*
-rwxr-xr-x 1 root root     388 Mär 28 03:39 /usr/bin/python3-pasteurize*
-rwxr-xr-x 1 root root     152 Apr  9 21:32 /usr/bin/python3-pbr*
-rwxr-xr-x 1 root root     384 Dez 17 13:47 /usr/bin/python3-unit2*
lrwxrwxrwx 1 root root      58 Feb 18 02:49 /usr/bin/pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py*

apt-get我尝试使用和重新安装 python3 包dpkg,但都失败了:

使用apt-get install选项:

root@******:/home/****# sudo apt-get install python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3 is already the newest version (3.8.2-0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
1 not fully installed or removed.
Need to get 0 B/47,6 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
dpkg: error processing package python3 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 python3
E: Sub-process /usr/bin/dpkg returned an error code (1)

使用apt-get install --reinstall选项:

root@******:/home/****# sudo apt-get install --reinstall python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly instaslled, 1 reinstalled, 0 to remove and 8 not upgraded.
1 not fully installed or removed.
Need to get 0 B/47,6 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 325889 files and directories currently installed.)
Preparing to unpack .../python3_3.8.2-0ubuntu2_amd64.deb ...
/var/lib/dpkg/info/python3.prerm: 5: py3clean: Permission denied
dpkg: warning: old python3 package pre-removal script subprocess returned error exit status 126
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 5: py3clean: Permission denied
dpkg: error processing archive /var/cache/apt/archives/python3_3.8.2-0ubuntu2_amd64.deb (--unpack):
 new python3 package pre-removal script subprocess returned error exit status 126
/var/lib/dpkg/info/python3.postinst: 47: py3compile: Permission denied
dpkg: error while cleaning up:
 installed python3 package post-installation script subprocess returned error exit status 126
Errors were encountered while processing:
 /var/cache/apt/archives/python3_3.8.2-0ubuntu2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

使用dpkg

root@****:/home/****# dpkg -i /var/cache/apt/archives/python3_3.8.2-0ubuntu2_amd64.deb 
(Reading database ... 325889 files and directories currently installed.)
Preparing to unpack .../python3_3.8.2-0ubuntu2_amd64.deb ...
/var/lib/dpkg/info/python3.prerm: 5: py3clean: Permission denied
dpkg: warning: old python3 package pre-removal script subprocess returned error exit status 126
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 5: py3clean: Permission denied
dpkg: error processing archive /var/cache/apt/archives/python3_3.8.2-0ubuntu2_amd64.deb (--install):
 new python3 package pre-removal script subprocess returned error exit status 126
/var/lib/dpkg/info/python3.postinst: 47: py3compile: Permission denied
dpkg: error while cleaning up:
 installed python3 package post-installation script subprocess returned error exit status 126
Errors were encountered while processing:
 /var/cache/apt/archives/python3_3.8.2-0ubuntu2_amd64.deb

答案1

我发现了错误。不知何故/usr/bin/python3.8丢失了可执行位(可能是因为我搞错了一个命令;这一天太漫长了)。我通过运行以下命令修复了它:

sudo chmod +x /usr/bin/python3.8

相关内容