安装python3.10要先升级ssl
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
安装python3
1:安装"Development tools" 软件组,其中包含编译和开发工具
yum -y groupinstall Development tools
2:安装 Python3 编译和运行所需的开发库和依赖项
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
3:安装 libffi 开发库和 zlib1g-dev 包,它们是 Python 编译和运行的额外依赖项
yum install -y libffi-devel zlib1g-dev
4:安装所有以 "zlib" 开头的软件包,以满足可能的 zlib 依赖项
yum install zlib* -y
- 下载源码包
wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tar.xz
- 解压
tar xf Python-3.10.13.tar.xz
7.创建python3的安装目录
mkdir /usr/local/python3
升级 GCC 版本
1:安装 CentOS 软件集和编译工具链
yum install -y centos-release-scl
yum install -y devtoolset-8-toolchain
2:启用新的工具链
scl enable devtoolset-8 bash
编译并安装 Python 3.10
1:进入pythin目录
cd Python-3.10.13
2:运行 Python 配置脚本,配置编译参数
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto --enable-shared --enable-optimizations
3:编译安装
make -j && make install
4.加入环境变量
vim /etc/profile
export PATH=/usr/local/python3/bin:$PATH
- 向 /etc/ld.so.conf 文件中添加新的库路径
echo "/usr/local/python3/lib" >> /etc/ld.so.conf
ldconfig -v