CentOS 7 上安装 Python 3.10

1. 安装依赖

yum groupinstall "Development Tools"

yum install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel xz-devel

2. 安装OpenSSL1.1.1

wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz --no-check-certificate

tar zxf openssl-1.1.1s.tar.gz

cd openssl-1.1.1s

./config --prefix=/usr/local/openssl-1.1.1

make && make install

3. 安装Python3.10

 wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz

tar xzf Python-3.10.8.tgz

cd Python-3.10.8

vim Modules/Setup

取消 Modules/Setup 里以下几行的注释并修改SSL=目标目录

==============================================

SSL=/usr/local/openssl-1.1.1

_ssl _ssl.c \

    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

    -L$(SSL)/lib -lssl -lcrypto

==============================================


export LD_RUN_PATH=/usr/local/openssl-1.1.1/lib/

./configure --enable-optimizations --with-openssl=/usr/local/openssl-1.1.1

(如果开优化编译失败,就取消优化, 去掉上面的  --enable-optimizations)

make altinstall

4. 检查 Python 版本

python3.10 --version

5. 安装setuptools 

如果在安装其他包时遇到没有setuptools的错误提示,需要手工更新setuptools

pip3 install --upgrade setuptools

如果在安装其他包时遇到ModuleNotFoundError: No module named ‘_ctypes’的错误,需要在命令行执行

yum install libffi-devel

然后重新执行

make altinstall

你可能感兴趣的:(CentOS 7 上安装 Python 3.10)