依赖
sudo yum groupinstall -y "Development Tools"
sudo yum install -y epel-release
sudo yum install -y wget zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
下包
cd /opt
sudo wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
解包
sudo tar xzf Python-3.10.0.tgz
安装
cd Python-3.10.0
sudo ./configure --enable-optimizations
sudo make altinstall
altinstall
参数用于避免覆盖系统自带的 python
命令。
验证
python3.10 --version
换源
mkdir pip
vi pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
附录
连接不到OpenSSL 库,报如下错误:
Could not fetch URL https://mirrors.aliyun.com/pypi/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='mirrors.aliyun.com', port=443): Max retries exceeded with url: /pypi/simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
解决
安装OpenSSL 库
cd ../
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
tar xzf openssl-1.1.1l.tar.gz
cd openssl-1.1.1l
sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
sudo make
sudo make install
echo "/usr/local/ssl/lib" | sudo tee -a /etc/ld.so.conf.d/openssl-1.1.1l.conf
重新编译python
cd ../Python-3.10.0
sudo ./configure --enable-optimizations --with-openssl=/usr/local/ssl
sudo make altinstall
验证
python3.10 -m pip install requests
评论区