【问题标题】:How to remove Python2 in Ubuntu?如何在 Ubuntu 中删除 Python2?
【发布时间】:2020-07-13 00:17:54
【问题描述】:

我通过虚拟机安装了 Ubuntu,并且预装了 Python3。我想试用一个用 Python2 制作的包,所以我安装了 Python 2.7(它成为默认的 Python)和 Anaconda2。

现在我已经完成了这个包,我删除了 anaconda2,我也想删除 Python2,但是如果它是默认的,我担心它会破坏我的系统。如何以安全的方式进行操作?

(base) me@me-VirtualBox:~$ whereis python
python: /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python2.7-config /usr/bin/python /usr/bin/python2.7 /usr/lib/python3.7 /usr/lib/python3.6 /usr/lib/python3.8 /usr/lib/python2.7 /etc/python3.6 /etc/python /etc/python2.7 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.6m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
(base) me@me-VirtualBox:~$ which python
/usr/bin/python

【问题讨论】:

    标签: python python-2.7 ubuntu uninstallation


    【解决方案1】:

    你可以使用:

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
    

    将其设置为默认值,不删除python2.7

    这将指向命令python 使用/usr/bin/python3.6

    或者如果update-alternatives --list python 显示多个结果,您可以交互选择使用哪个版本::

    update-alternatives --config python
    

    【讨论】:

    • 第一个命令给了我错误:“update-alternatives:错误:错误创建符号链接'/etc/alternatives/python.dpkg-tmp':权限被拒绝”。输入“update-alternatives --list python”时,我收到错误“no alternatives for python”。
    • 我更新了我的答案。请尝试在前面加上sudo,因为这样的更改需要root权限。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2018-01-17
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    相关资源
    最近更新 更多