系统相关
首页 > 系统相关> > Ubuntu18.04系统py2与py3切换方法

Ubuntu18.04系统py2与py3切换方法

作者:互联网

前言

Ubuntu18.04系统在安装python时会安装两个版本:2.7和3.6.默认情况下系统环境使用的是python2,但是我们有时需要使用python3来作为我们的开发环境,所以需要自由切换python版本.
python2切换成python3

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

执行上面两句命令即可将2.7版本切换成python3.6版本,想要查看是否切换成功:

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ python --version
Python 3.6.5
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ 

python3切换成python2

shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ sudo update-alternatives --config python
[sudo] shanlei 的密码: 
有 2 个候选项可用于替换 python (提供 /usr/bin/python)。
 
  选择       路径            优先级  状态
------------------------------------------------------------
* 0            /usr/bin/python3   150       自动模式
  1            /usr/bin/python2   100       手动模式
  2            /usr/bin/python3   150       手动模式
 
要维持当前值[*]请按<回车键>,或者键入选择的编号:1
update-alternatives: 使用 /usr/bin/python2 来在手动模式中提供 /usr/bin/python (python)
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ python --version
Python 2.7.15rc1
shanlei@shanlei-Lenovo-ideapad-110-15ISK:~$ 

之后我们在切换python版本时就可以使用这个命令键入选择进行切换了:

sudo update-alternatives --config python

标签:bin,python,py2,py3,shanlei,python2,Ubuntu18.04,python3,usr
来源: https://blog.csdn.net/Xiaomoxie/article/details/120885244