gpt4 book ai didi

python - 如何在 Ubuntu 中删除 Python2?

转载 作者:行者123 更新时间:2023-12-04 18:27:47 26 4
gpt4 key购买 nike

我通过虚拟机安装了 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

最佳答案

您可以使用:

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

关于python - 如何在 Ubuntu 中删除 Python2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60967660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com