卸载 python3 后如何解决 dpkg 错误?

卸载 python3 后如何解决 dpkg 错误?

我尝试python3.5从我的Ubuntu 16.04sudo apt-get remove python3通过使用目录中的命令/usr/bin。当我尝试使用再次安装它时sudo apt-get install python3,我收到以下错误:

>> /usr/bin$ sudo apt-get remove python3
>> Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'python3' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  gir1.2-glib-2.0 libexpat1-dev libgirepository-1.0-1 libpython3-dev libpython3.5-dev python-pip-whl python-pycurl python3.5-dev
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.


>> python3 -V
>> bash: /usr/bin/python3: No such file or directory

>> sudo apt-get install python3
>> Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gir1.2-glib-2.0 libexpat1-dev libgirepository-1.0-1 libpython3-dev libpython3.5-dev python-pip-whl python-pycurl python3.5-dev
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  dh-python
Suggested packages:
  python3-doc python3-tk python3-venv
The following NEW packages will be installed:
  dh-python python3
0 upgraded, 2 newly installed, 0 to remove and 61 not upgraded.
Need to get 0 B/82.7 kB of archives.
After this operation, 436 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package dh-python.
(Reading database ... 180938 files and directories currently installed.)
Preparing to unpack .../dh-python_2.20151103ubuntu1.2_all.deb ...
Unpacking dh-python (2.20151103ubuntu1.2) ...
Selecting previously unselected package python3.
Preparing to unpack .../python3_3.5.1-3_amd64.deb ...
Unpacking python3 (3.5.1-3) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python3 (3.5.1-3) ...
running python rtupdate hooks for python3.5...
/usr/share/python3/runtime.d/dh-python.rtupdate: 5: /usr/share/python3/runtime.d/dh-python.rtupdate: py3clean: not found
error running python rtupdate hook dh-python
dpkg: error processing package python3 (--configure):
 subprocess installed post-installation script returned error exit status 4
dpkg: dependency problems prevent configuration of dh-python:
 dh-python depends on python3:any (>= 3.3.2-2~); however:
  Package python3 is not configured yet.

dpkg: error processing package dh-python (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python3
 dh-python
E: Sub-process /usr/bin/dpkg returned an error code (1)


>> whereis python3
>> python3: /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python3.5m /usr/bin/python3 /usr/lib/python3.5 /usr/lib/python3.6 /usr/lib/python3 /etc/python3.5 /etc/python3.6 /etc/python3 /usr/local/lib/python3.5 /usr/local/lib/python3.6 /usr/share/python3 /usr/share/man/man1/python3.1.gz

请提出解决方案。

答案1

如果你想确保软件包被彻底删除,请使用“purge”选项。这也会删除所有配置文件。

sudo apt purge python3
sudo apt-get purge python3

您也可以使用“*”,但这实际上会删除以 python3 开头的所有内容。

sudo apt purge python3*

但正如许多评论中所提到的删除系统 Python 是一个坏主意。 因此,为了更好地控制删除,请检查仍然安装的内容。

dpkg -l | grep -E '*python*' | less

或者,您可以直接在安装目录中查找。

ls /usr/bin/python

这样你就可以检查你安装了哪些 Python 包。如果你想删除它们,还可以查看它们的确切名称。

在我看来,当你运行时:

sudo apt-get install python3

它尝试仅安装“dh-python”包,因为它仍然发现已安装了一些 python 包。它还告诉您 python3 尚未配置。因此看起来它已安装,但由于您之前尝试删除它,配置不正确,因此无法安装“dh-python”。因此,正确删除 python3 包及其配置文件(之前由您安装,而不是由系统安装)应该可以让您正确安装它...

编辑

在删除 Python 之前,请尝试:

sudo dpkg-reconfigure python3*

对于你的情况,它将是:

sudo dpkg-reconfigure python3.5*

如果您决定删除 python。(您安装的版本,而不是系统安装的版本)请务必检查依赖于它的内容。这里你可以看看如何。

相关内容