无法卸载Python 3.6

我想卸载我的3.6版本,而不影响原来的3.5版本。所以我运行了以下命令:
sudo apt-get remove python3.6

但是输出结果是:
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'

$ dpkg -l python3.6
dpkg-query: no packages found matching python3.6

$ dpkg -l python3
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  python3        3.5.1-3      amd64        interactive high-level object-ori

$ apt-cache policy python3
python3:
  Installed: 3.5.1-3
  Candidate: 3.5.1-3
  Version table:
 *** 3.5.1-3 500
        500 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status

我的目标在Ubuntu 16.04 : Can't seem to make numpy work in python 3.6.5 but it works fine in python 2.7.12中有所描述。无论是在python2.7、python3.5还是python3.6中,我都无法使我的代码运行起来。只要能够运行我的代码,我对Python的版本没有任何要求。
$ type python
python is hashed (/usr/bin/python)
$ type python3
python3 is hashed (/usr/local/bin/python3)
$ type python3.6
python3.6 is hashed (/usr/local/bin/python3.6)

$ apt list --installed 'python*'
Listing... Done
python/xenial-updates,now 2.7.12-1~16.04 amd64 [installed]
python-all/xenial-updates,now 2.7.12-1~16.04 amd64 [installed,automatic]
python-all-dev/xenial-updates,now 2.7.12-1~16.04 amd64 [installed,automatic]
python-apt-common/xenial-updates,xenial-updates,now 1.1.0~beta1ubuntu0.16.04.1 all [installed]
python-crypto/xenial-updates,xenial-security,now 2.6.1-6ubuntu0.16.04.3 amd64 [installed]
python-dbus/xenial,now 1.2.0-3 amd64 [installed,automatic]
python-dev/xenial-updates,now 2.7.12-1~16.04 amd64 [installed,automatic]
python-gi/xenial,now 3.20.0-0ubuntu1 amd64 [installed,automatic]
python-ldb/xenial,now 2:1.1.24-1ubuntu3 amd64 [installed]
python-minimal/xenial-updates,now 2.7.12-1~16.04 amd64 [installed]
python-numpy/xenial,now 1:1.11.0-1ubuntu1 amd64 [installed]
python-pip/xenial-updates,xenial-updates,now 8.1.1-2ubuntu0.4 all [installed]
python-pip-whl/xenial-updates,xenial-updates,now 8.1.1-2ubuntu0.4 all [installed,automatic]
python-pkg-resources/xenial,xenial,now 20.7.0-1 all [installed,automatic]
python-pyatspi/xenial,xenial,now 2.18.0+dfsg-3 all [installed,automatic]
python-samba/xenial-updates,xenial-security,now 2:4.3.11+dfsg-0ubuntu0.16.04.13 amd64 [installed]
python-setuptools/xenial,xenial,now 20.7.0-1 all [installed,automatic]
python-talloc/xenial,now 2.1.5-2 amd64 [installed]
python-tdb/xenial,now 1.3.8-2 amd64 [installed]
python-wheel/xenial,xenial,now 0.29.0-1 all [installed,automatic]
python2.7/xenial-updates,now 2.7.12-1ubuntu0~16.04.3 amd64 [installed]
python2.7-dev/xenial-updates,now 2.7.12-1ubuntu0~16.04.3 amd64 [installed,automatic]
python2.7-minimal/xenial-updates,now 2.7.12-1ubuntu0~16.04.3 amd64 [installed]
python3/xenial,now 3.5.1-3 amd64 [installed]
python3-apport/xenial-updates,xenial-updates,now 2.20.1-0ubuntu2.17 all [installed]
python3-apt/xenial-updates,now 1.1.0~beta1ubuntu0.16.04.1 amd64 [installed]
python3-aptdaemon/xenial,xenial,now 1.1.1+bzr982-0ubuntu14 all [installed]
python3-aptdaemon.gtk3widgets/xenial,xenial,now 1.1.1+bzr982-0ubuntu14 all [installed]
python3-aptdaemon.pkcompat/xenial,xenial,now 1.1.1+bzr982-0ubuntu14 all [installed]
python3-blinker/xenial,xenial,now 1.3.dfsg2-1build1 all [installed]
python3-brlapi/xenial-updates,now 5.3.1-2ubuntu2.1 amd64 [installed]
python3-bs4/xenial,xenial,now 4.4.1-1 all [installed]
python3-cairo/xenial,now 1.10.0+dfsg-5build1 amd64 [installed]
python3-cffi-backend/xenial,now 1.5.2-1ubuntu1 amd64 [installed]
python3-chardet/xenial,xenial,now 2.3.0-2 all [installed]
python3-checkbox-support/xenial,xenial,now 0.22-1 all [installed]
python3-commandnotfound/xenial-updates,xenial-updates,now 0.3ubuntu16.04.2 all [installed]
python3-cryptography/xenial-updates,xenial-security,now 1.2.3-1ubuntu0.1 amd64 [installed]
python3-cups/xenial,now 1.9.73-0ubuntu2 amd64 [installed]
python3-cupshelpers/xenial,xenial,now 1.5.7+20160212-0ubuntu2 all [installed]
python3-dateutil/xenial,xenial,now 2.4.2-1 all [installed,automatic]
python3-dbus/xenial,now 1.2.0-3 amd64 [installed]
python3-debian/xenial,xenial,now 0.1.27ubuntu2 all [installed]
python3-defer/xenial,xenial,now 1.0.6-2build1 all [installed]
python3-dev/xenial,now 3.5.1-3 amd64 [installed,automatic]
python3-distupgrade/xenial-updates,xenial-updates,xenial-security,xenial-security,now 1:16.04.25 all [installed]
python3-feedparser/xenial,xenial,now 5.1.3-3build1 all [installed]
python3-gdbm/xenial,now 3.5.1-1 amd64 [installed]
python3-gi/xenial,now 3.20.0-0ubuntu1 amd64 [installed]
python3-gi-cairo/xenial,now 3.20.0-0ubuntu1 amd64 [installed]
python3-guacamole/xenial,xenial,now 0.9.2-1 all [installed]
python3-html5lib/xenial,xenial,now 0.999-4 all [installed]
python3-httplib2/xenial,xenial,now 0.9.1+dfsg-1 all [installed]
python3-icu/xenial,now 1.9.2-2build1 amd64 [installed]
python3-idna/xenial,xenial,now 2.0-3 all [installed]
python3-jinja2/xenial,xenial,now 2.8-1 all [installed]
python3-jwt/xenial-updates,xenial-updates,xenial-security,xenial-security,now 1.3.0-1ubuntu0.1 all [installed]
python3-louis/xenial-updates,xenial-updates,xenial-security,xenial-security,now 2.6.4-2ubuntu0.1 all [installed]
python3-lxml/xenial,now 3.5.0-1build1 amd64 [installed]
python3-mako/xenial,xenial,now 1.0.3+ds1-1ubuntu1 all [installed]
python3-markupsafe/xenial,now 0.23-2build2 amd64 [installed]
python3-minimal/xenial,now 3.5.1-3 amd64 [installed]
python3-oauthlib/xenial,xenial,now 1.0.3-1 all [installed]
python3-padme/xenial,xenial,now 1.1.1-2 all [installed]
python3-pam/xenial,now 0.4.2-13.2ubuntu2 amd64 [installed]
python3-pexpect/xenial,xenial,now 4.0.1-1 all [installed]
python3-pil/xenial-updates,xenial-security,now 3.1.2-0ubuntu1.1 amd64 [installed]
python3-pip/xenial-updates,xenial-updates,now 8.1.1-2ubuntu0.4 all [installed]
python3-pkg-resources/xenial,xenial,now 20.7.0-1 all [installed]
python3-plainbox/xenial,xenial,now 0.25-1 all [installed]
python3-problem-report/xenial-updates,xenial-updates,now 2.20.1-0ubuntu2.17 all [installed]
python3-ptyprocess/xenial,xenial,now 0.5-1 all [installed]
python3-pyasn1/xenial,xenial,now 0.1.9-1 all [installed]
python3-pyatspi/xenial,xenial,now 2.18.0+dfsg-3 all [installed]
python3-pycurl/xenial,now 7.43.0-1ubuntu1 amd64 [installed]
python3-pyparsing/xenial-updates,xenial-updates,now 2.0.3+dfsg1-1ubuntu0.1 all [installed]
python3-renderpm/xenial,now 3.3.0-1 amd64 [installed]
python3-reportlab/xenial,xenial,now 3.3.0-1 all [installed]
python3-reportlab-accel/xenial,now 3.3.0-1 amd64 [installed]
python3-requests/xenial,xenial,now 2.9.1-3 all [installed]
python3-setuptools/xenial,xenial,now 20.7.0-1 all [installed,automatic]
python3-six/xenial,xenial,now 1.10.0-3 all [installed]
python3-software-properties/xenial-updates,xenial-updates,now 0.96.20.7 all [installed]
python3-speechd/xenial,xenial,now 0.8.3-1ubuntu3 all [installed]
python3-systemd/xenial,now 231-2build1 amd64 [installed]
python3-tk/xenial,now 3.5.1-1 amd64 [installed]
python3-uno/xenial-updates,xenial-security,now 1:5.1.6~rc2-0ubuntu1~xenial3 amd64 [installed]
python3-update-manager/xenial-updates,xenial-updates,xenial-security,xenial-security,now 1:16.04.12 all [installed]
python3-urllib3/xenial-updates,xenial-updates,now 1.13.1-2ubuntu0.16.04.1 all [installed]
python3-wheel/xenial,xenial,now 0.29.0-1 all [installed,automatic]
python3-xdg/xenial,xenial,now 0.25-4 all [installed]
python3-xkit/xenial,xenial,now 0.5.0ubuntu2 all [installed]
python3-xlsxwriter/xenial,xenial,now 0.7.3-1 all [installed]
python3.5/xenial-updates,xenial-security,now 3.5.2-2ubuntu0~16.04.4 amd64 [installed]
python3.5-dev/xenial-updates,xenial-security,now 3.5.2-2ubuntu0~16.04.4 amd64 [installed,automatic]
python3.5-minimal/xenial-updates,xenial-security,now 3.5.2-2ubuntu0~16.04.4 amd64 [installed]

为什么要卸载 Python3?你可以同时安装两个版本。只需在命令行中指定解释器,如 python2,或者在 shebang(注释开头)中使用 #!/usr/bin/python2 - solsTiCe
我现在可以在终端中使用python3.5运行我的代码了 :-) 但是还不知道如何使用python3或者python来运行它。 - goalpost
1答案取决于您安装Py3.6的方法,回顾一下您的笔记(或记忆)。如果您能提供您遵循的原始指令的链接,那就更好了。例如,apt只能删除deb软件包 - 它无法识别pip、flatpack或tar等。 - user535733
1@SHREYASHANARASE 感谢您提供的额外信息。很奇怪 dpkg 显示 python3 版本为 3.6.5,而 apt 认为它是 python3/xenial,now 3.5.1-3 amd64。您能否在问题中添加 apt-cache policy python3 的输出?顺便问一下,您的 dpkg -l 输出是否与您报告的完全相同?我在 Ubuntu 16.04 上使用相同的命令得到了另一种格式:ii python3 3.5.1-3 amd64 interactive high-level object-oriented lang - Melebius
2个回答

你的python3python3.6二进制文件1安装在/usr/local/bin,这不是默认位置,dpkg(或APT)并不知道它们。所以它们很可能不是通过dpkg或APT安装的。要卸载它们,只需从/usr/local/bin文件夹中删除它们。

初步检查

我建议先将它们重命名:

sudo mv /usr/local/bin/python3 /usr/local/bin/python3.bak
sudo mv /usr/local/bin/python3.6 /usr/local/bin/python3.6.bak

然后检查当你运行python3时,APT安装的版本是否生效:
python3 --version # expected output: Python 3.5.2

如果此检查成功,您可以安全地删除文件/usr/local/bin/python3.bak/usr/local/bin/python3.6.bak
实际上,一个文件可能是另一个文件的符号链接。

输出结果是:Python 3.5.2。我现在可以删除这些文件 /usr/local/bin/python3.bak/usr/local/bin/python3.6.bak 吗?我只想卸载 Python 3.6 并恢复一切正常。然后,也许以后我可以按照推荐的方式安装 Python 3.6,那是什么方式? - goalpost
是的,我可以确认,在我的情况下,它也返回Python 3.5.2,尽管软件包版本是3.5.1-3。所以看起来这是16.04的默认版本。要在Ubuntu 16.04上获取Python 3.6,您应该使用PPA:https://askubuntu.com/q/865554/250300 - Melebius

我想你可以使用以下命令:
sudo -i 进入 root 用户

然后使用:

apt purge python3-minimal 作为示例。

我今天尝试了这个方法,据我所知是有效的。

祝你好运!


欢迎来到[ubuntu.se],感谢您的建议!不过,很抱歉,您的回答在这种情况下可能行不通。当操作者无法完成apt-get remove时,他很可能也无法完成包含apt-get removeapt purge - Melebius