Ubuntu20.04安装Python2 Ubuntu 20.04安装Python 2 版本
python3遍布的时代,python27的安装教程已经很难到了,这⾥做下记录和避坑指南
安装Python 2
使⽤SSH终端连接到Ubuntu 20.04服务器并使⽤apt安装Python 2。
sudo apt install python2
检查Python版本,命令如下:
python2 -Vubuntu安装教程
检查可⽤的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/python
2  1        manual mode
2            /usr/bin/python
3  2        manual mode
输⼊您的选择,例如选择1来确定安装python2版本。
Press to keep the current choice[*], or type selection number: 1
最后,检查你的python版本
python -V
#回显Python 2.7.18rc1
⾄此,Ubuntu 20.04安装Python 2 版本过程结束。
pip安装
安装python2.7对应版本的pip
sudo wget bootstrap.pypa.io/pip/2.7/get-pip.pysudo python get-pip.py