美文网首页
ubuntu 上设置与切换默认 python 版本

ubuntu 上设置与切换默认 python 版本

作者: 与蟒唯舞 | 来源:发表于2017-06-26 10:02 被阅读144次

目前所有的 linux 系统默认版本都是 python2。

此方法适用于 ubuntu 和 debian,其他发行版本没有测试。正常情况基于 ubuntu 与 debian 开发的发行版本都支持。

打开终端分别输入下面两条命令:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

然后在终端输入:

python --version

如果无误,此时 python 版本应该切换到 python3 了。

如果需要重新切换回 python2,只需要在终端输入:

sudo update-alternatives --config python

然后选择你需要的 python 版本,输入序号回车即可。

因为系统很多程序依赖于 python2,如需要升级系统或者安装系统更新的时候,建议先切换到系统的默认版本 python2,否则可能出现依赖无法安装问题。

相关文章

网友评论

      本文标题:ubuntu 上设置与切换默认 python 版本

      本文链接:https://www.haomeiwen.com/subject/gfpdcxtx.html