我刚刚升级到 Ubuntu 20.04,之前从源代码编译了 python 3.8,当 Ubuntu 的默认版本现在是 python 3.8 时,这变得令人困惑。所以我手动删除了从源二进制文件编译的版本。只是在这个过程中,我不小心删除了系统版本的 python3。
以下是我迄今为止尝试过的:
[~] $ sudo dpkg -i python3_3.8.2-0ubuntu2_amd64.deb
(Reading database ... 568603 files and directories currently installed.)
Preparing to unpack python3_3.8.2-0ubuntu2_amd64.deb ...
running python pre-rtupdate hooks for python3.8...
Unpacking python3 (3.8.2-0ubuntu2) over (3.8.2-0ubuntu2) ...
dpkg: dependency problems prevent configuration of python3:
python3 depends on python3.8 (>= 3.8.2-1~); however:
Package python3.8 is not configured yet.
dpkg: error processing package python3 (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.9.1-1) ...
Errors were encountered while processing:
python3
这不起作用所以我尝试通过 apt
[~] $ sudo apt install -f 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 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python3.8 (3.8.5-1~20.04) ...
/var/lib/dpkg/info/python3.8.postinst: 9: /usr/bin/python3.8: not found
dpkg: error processing package python3.8 (--configure):
installed python3.8 package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of python3:
python3 depends on python3.8 (>= 3.8.2-1~); however:
Package python3.8 is not configured yet.
dpkg: error processing package python3 (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while proc
essing:
python3.8
python3
E: Sub-process /usr/bin/dpkg returned an error code (1)
据我所知,apt 依赖 python3?是真的吗?有什么解决方案可以强制重新安装 python3 吗?
更新:根据评论
sudo dpkg --configure python3.8
Setting up python3.8 (3.8.5-1~20.04) ...
/var/lib/dpkg/info/python3.8.postinst: 9: /usr/bin/python3.8: not found
dpkg: error processing package python3.8 (--configure):
installed python3.8 package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
python3.8
更新 2
/var/lib/dpkg/info/python3.8.postinst
通过运行sh /var/lib/dpkg/info/python3.8.postinst
(不确定是否有其他方式运行)没有产生任何输出。但是查看文件显示它正在调用被意外删除的 python3.8。
tom@computer[~] $ cat /var/lib/dpkg/info/python3.8.postinst
#! /bin/sh
set -e
case "$1" in
configure)
files=$(dpkg -L libpython3.8-stdlib:amd64 | sed -n '/^\/usr\/lib\/python3.8\/.*\.py$/p')
if [ -n "$files" ]; then
/usr/bin/python3.8 -E -S /usr/lib/python3.8/py_compile.py $files
if grep -sq '^byte-compile[^#]*optimize' /etc/python/debian_config; then
/usr/bin/python3.8 -E -S -O /usr/lib/python3.8/py_compile.py $files
fi
else
echo >&2 "python3.8: can't get files for byte-compilation"
fi
esac
exit 0
tom@computer[~] $ /usr/bin/python3.8
-bash: /usr/bin/python3.8: No such file or directory
答案1
您安装的版本比原先的版本旧了一个版本。它python3_3.8.2-0ubuntu2
至少需要python3.8 (>= 3.8.2-1~)
我的缓存中可用的最旧版本。如果您再次遇到已配置的错误,请使用它。用于dpkg --configure -a
配置未配置的软件包。您可以选择从 Ubuntu 的服务器下载我下面显示的最新版本或与您的安装同步的最新 3.8.5。您可以在软件包站点上搜索 Ubuntu,或者如果可能的话使用 apt 来获取所需的文件。
root@zeus-H370M:~# apt-cache policy python3.8
python3.8:
Installed: 3.8.5-1~20.04
Candidate: 3.8.5-1~20.04
Version table:
*** 3.8.5-1~20.04 500
500 http://ca.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
100 /var/lib/dpkg/status
3.8.2-1ubuntu1 500
500 http://ca.archive.ubuntu.com/ubuntu focal/main amd64 Packages
root@zeus-H370M:~# cat /etc/os-release | grep PRETTY
PRETTY_NAME="Ubuntu 20.04.2 LTS"
然后总是有手动解决方案,ar x file.deb
如果需要,解压并将文件移动到位,然后编辑状态文件/var/lib/dpkg/status
以告知它已安装,然后再试一次。如果在 / 处提取,我认为会将它们放在正确的位置,以确保万无一失,我会创建目录并在其中提取,然后移动到位。