ubuntu 错误地破坏了 python 安装

max*_*odr 8 python ubuntu system-administration

我尝试更新 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).
Run Code Online (Sandbox Code Playgroud)

我尝试手动安装以将 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).
Run Code Online (Sandbox Code Playgroud)

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

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

max*_*odr 23

经过更多研究后,我创建了一篇与 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
Run Code Online (Sandbox Code Playgroud)

第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
Run Code Online (Sandbox Code Playgroud)

步骤 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
Run Code Online (Sandbox Code Playgroud)

步骤4。

cd /tmp/missing
ls -lR /tmp/missing  # if you are curious about overwriting your HD
sudo cp -rpfv /tmp/missing/*  /
Run Code Online (Sandbox Code Playgroud)

步骤 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.
>>>
Run Code Online (Sandbox Code Playgroud)

导入并测试新版本:

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

步骤 6。

rm -rf /tmp/missing
Run Code Online (Sandbox Code Playgroud)

步骤 7。

dpkg -s -a python3.5 | grep  reinstreq
# Any listing also needs to be reinstalled along with python3
apt-get install --reinstall python3
Run Code Online (Sandbox Code Playgroud)

步骤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>>)
Run Code Online (Sandbox Code Playgroud)

步骤 9.

尝试安装通用道具。

sudo apt install software-properties-common
Run Code Online (Sandbox Code Playgroud)

如果有效,那么现在安装已完成。


我已经在 Ubuntu 16.04 上尝试过此操作,可以正常安装 Python2.7,但不能使用 Python3 或 Python3.5。我最初安装的是Python3.5,这就是为什么尝试安装该版本而不是最新版本。

  • 这拯救了我的一天 (4认同)
  • 我们被告知这是不可能的,需要重新安装操作系统......这需要成为一篇文章。我让它在 ubuntu 22.04 和 Python3.10 上为我工作。 (2认同)