yum 方式安装
查看当前 python 版本
python -V
如果不是 2.7.x,更新版本
yum install scl-utils
yum install centos-release-scl-rh
yum install python27
scl enable python27 bash
执行 sudo scl enable python27 bash
返回
Unable to open /etc/scl/prefixes/python27!
解决方法是:
sudo yum install epel-release
sudo rpm -ivh https://rhel6.iuscommunity.org/ius-release.rpm
sudo yum --enablerepo=ius install python27 python27-devel python27-pip python27-setuptools python27-virtualenv -y
安装 yum-utils
sudo yum install yum-util
源码方式安装
下载 python 2.7
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
解压文件
tar xzf Python-2.7.18.tgz
安装 python
cd Python-2.7.18
./configure --enable-optimizations
sudo make altinstall
用 make altinstall
避免覆盖旧版本的 python
验证 python 版本
python2.7 -V
Python 2.7.18
安装 pip
下载 py 文件并安装
wget https://bootstrap.pypa.io/get-pip.py
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
sudo python2.7 get-pip.py
验证 pip 版本
sudo pip2.7 --version
pip 20.1.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
以后就可以用 pip2.7 安装 python 模块和包了
sudo pip2.7 install supervisor