Ubuntu 20.04安裝Python 2 版本
python3遍布的時代,python27的安裝教程已經很難找到了,這里做下記錄和避坑指南
安裝Python 2
使用SSH終端連接到Ubuntu 20.04服務器並使用apt安裝Python 2。
sudo apt install python2
檢查Python版本,命令如下:
python2 -V
檢查可用的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
輸入您的選擇,例如選擇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 https://bootstrap.pypa.io/pip/2.7/get-pip.pysudo python get-pip.py