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 -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
posted @ 2021-08-14 21:37  知己呀  阅读(4724)  评论(0编辑  收藏  举报