Loading

Ubuntu-18.04Python2与Python3自由切换

一、配置ssh链接

  • 安装openssh-server
devops@devops-virtual-machine:~$ sudo apt-get install openssh-server

二、安装Python3及pip3

devops@devops-virtual-machine:~$ sudo apt-get install python3
devops@devops-virtual-machine:~$ sudo apt install python3-pip

三、将Python3设置为默认

python2切换python3

devops@devops-virtual-machine:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
devops@devops-virtual-machine:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

验证

devops@devops-virtual-machine:~$ python --version
Python 3.6.5

Python3切换至Python2

devops@devops-virtual-machine:~$ sudo update-alternatives --config python
有 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)
devops@devops-virtual-machine:~$ python --version
Python 2.7.15rc1

Python2切换至Python3

devops@devops-virtual-machine:~$ sudo update-alternatives --config python
有 2 个候选项可用于替换 python (提供 /usr/bin/python)。

  选择       路径            优先级  状态
------------------------------------------------------------
  0            /usr/bin/python3   150       自动模式
* 1            /usr/bin/python2   100       手动模式
  2            /usr/bin/python3   150       手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:0
update-alternatives: 使用 /usr/bin/python3 来在自动模式中提供 /usr/bin/python (python)
devops@devops-virtual-machine:~$ python --version
Python 3.6.5

 

posted @ 2018-08-01 20:11  KubeSec  阅读(10824)  评论(0编辑  收藏  举报