Python 2功能已经从Ubuntu20.04操作系统中移除了,但如果你需要旧版本的Python的加,还是可以安装和配置的。最近小编给我的惠主机www.idccoupon.com网站就安装了Python 2,下面大概说下安装过程。
安装Python 2
使用SSH终端连接到Ubuntu 20.04服务器并使用apt安装Python 2。$ sudo apt install python2
检查Python版本,命令如下:$ python2 -V
Python 2.7.17
检查可用的Python版本
检查系统上可用的Python版本,命令如下:$ ls /usr/bin/python*
/usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.8
查看是否配置了Python替代版本方案,命令如下:$ sudo update-alternatives --list python
update-alternatives: error: no alternatives for python
设置Python替代版本
在这里,我将设置两个Python替代:Python2和Python3版本。$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
确认两个备选方案都可以使用,命令如下:$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3
接下来选择可选的Python版本。$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3 2 auto mode
1 /usr/bin/python2 1 manual mode
2 /usr/bin/python3 2 manual mode
Press to keep the current choice[*], or type selection number: 1
输入您的选择,例如选择1来确定安装python2版本。
最后,检查你的python版本:$ python -V
Python 2.7.18rc1
至此,Ubuntu 20.04安装Python 2 版本过程结束。