ubuntu错误地破坏了python的安装



我试图更新Python,但我不知道版本的隔离,而是删除了版本,所以,我已经删除了Ubuntu 16.04 VPS中的所有Python版本。现在我无法通过apt-get安装任何东西。

root@vps15:/# apt-get install --reinstall python3.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
dh-python : Depends: python3:any (>= 3.3.2-2~)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

我尝试手动将Python 2.7源代码安装到/usr/lib,现在可以使用了,但现在的问题是这个依赖关系:;dh-python";。

# apt-get install python3.5-minimal
Reading package lists... Done
Building dependency tree      
Reading state information... Done
python3.5-minimal is already the newest version (3.5.2-2ubuntu0~16.04.5).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
python3.5-minimal : Depends: libpython3.5-minimal (= 3.5.2-2ubuntu0~16.04.5) but it is not installable
Recommends: python3.5 but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

我已经尝试了列出的所有方法,但无法修复依赖关系。

在尝试修复之前,问题是Python2.7,而不是python3,现在手动安装的python3.没有修复问题。

经过更多的研究,我创建了一个与Debian相关的帖子。为Ubuntu 16.04处理一些修改,尝试了这个指南,现在一切正常:

步骤1

cd /tmp
apt-get download libpython3.5-minimal
apt-get download python3.5-minimal
apt-get download python3-minimal
apt-get download libpython3.5-stdlib
apt-get download python3.5

步骤2

rm -rf /usr/local/lib/python3.5*
rm -rf /usr/local/bin/python3.5*
update-alternatives --remove python3 /usr/local/bin/python3.5
hash -r  # removes cached python3 binary path

步骤3

cd /tmp
dpkg-deb -x libpython3.5-minimal_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x libpython3.5-stdlib_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3.5-minimal_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3.5_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3-minimal_3.5.1-3_amd64.deb missing

步骤4

cd /tmp/missing
ls -lR /tmp/missing  # if you are curious about overwriting your HD
sudo cp -rpfv /tmp/missing/*  /

步骤5

python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

导入并测试新版本:

>>> import sys
>>> print(sys.version_info)
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
>>>
>>> quit()

步骤6

rm -rf /tmp/missing

步骤7

dpkg -s -a python3.5 | grep  reinstreq
# Any listing also needs to be reinstalled along with python3
apt-get install --reinstall python3

步骤8

apt-get autoclean
apt-get autoremove
# (see the packages that will autoremove, you need to reinstall it again after: apt-get install --fix-broken --reinstall <<packages>>)

步骤9

试着安装普通道具。

sudo apt install software-properties-common

如果它工作,现在安装完成。


我在Ubuntu 16.04上尝试过这一点,安装了Python2.7,但没有安装Python3或Python3.5。我最初安装的是Python3.5,这就是为什么我尝试安装最新版本。

感谢您为我指出根本原因。对我来说,问题是pip安装的distro_info软件包损坏,而pip本身损坏严重,我无法通过pip uninstall卸载该软件包。我删除了/usr/local/lib/python3.8,所以do-release-upgrade将使用/usr/lib/python3.8下的原始Ubuntu包。这解决了问题。我是从20.04更新的=>22.04.

最新更新