由于Ubuntu 20.04版本移除了早先版本自带的Python2.7,所以如果需要使用Python2时必须先安装Python2.7

 

一、配置ssh链接

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

 

二、安装Python2.7

hades@monster-virtual-machine:~$ sudo apt-get install python2.7

 

三、配置替换方案

hades@monster-virtual-machine:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 100
hades@monster-virtual-machine:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 150

update-alternatives命令相关说明

https://blog.csdn.net/williamfan21c/article/details/53413871

 

四、查看替换方案

 

hades@monster-virtual-machine:~$ sudo update-alternatives --list python

 

可以看到当前系统中存在的配置方案(见下图)

 

五、Python2和Python3的快速切换

  • 切换步骤
  1. 打开配置选择方案
  2. 在选择替代方案界面输入方案编号

  实际命令和相关显示

hades@monster-virtual-machine:~$ sudo update-alternatives --config python

  系统会显示可选择的替代方案,输入所需要的方案编号,此处选择1,将python命令链接到python2.7

 

 

参考文章:

Ubuntu-18.04Python2与Python3自由切换

感谢文章的作者:hwlong

 

posted on 2020-09-04 14:08  大王背我来巡山®  阅读(63)  评论(0)    收藏  举报