1 安装依赖
python
sudo yum -y update
sudo yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel -y
sudo yum -y groupinstall "Development Tools"
2 安装必需的 openssl >= 1.1.1
python
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz --no-check-certificate
tar zxf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config --prefix=/usr/local/openssl-1.1.1
sudo make && sudo make install
3 安装python3.11.2
python
# 下载
wget https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tgz
# 解压
tar -xf Python-3.11.2.tgz
# 进入目标文件
cd Python-3.11.2
# 配置安装路径:/usr/local/python311
# 把python3.11.2 编译安装到/usr/local/python311路径下
./configure --prefix=/usr/local/python311
# 编译并安装,如果报错,说明缺依赖
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel -y
make && make install
# 建立软连接:/usr/local/python311路径不在环境变量,终端命令 python3,pip3
cd /usr/local/python311/bin
ln -s /usr/local/python311/bin/python3 /usr/bin/python3
ln -s /usr/local/python311/bin/pip3 /usr/bin/pip3
# 机器上有多个python和pip命令,对应关系如下
python 2.x pip
python3 3.6 pip3
python3.11 3.11 pip3.11
# 删除安装包与文件:
rm -rf Python-3.11.2
rm -rf Python-3.11.2.tgz
注意:使用pip3,报错
python
1 先安装EPEL
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2 将原有的备份epel.repo和epel-testing.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.back
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.back
3 重新安装epel.repo
sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
4 再运行如下命令,安装pip3
sudo yum install python3-pip