CentOS编译安装带有ssl模块的Python3.10.7解决pip install时提示SSLError

前言

2023/06/10更新:
优化了一些步骤

安装pipx时候遇到了下面的提示,记录一下解决过程。

WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError"Can't connect to HTTPS URL because the SSL module is not available.")':/pypi/simple/pipx

CentOS编译安装带有ssl模块的Python3.10.7解决pip install时提示SSLError_第1张图片

编译Python3.10.7

安装Yum源

yum install -y epel-release

依赖工具下载

yum install -y gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel wget

编译OpenSSL源码

Python3.10.7编译需要使用OpenSSL版本1.1.1的源码使用wget下载

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

解压编译openssl

tar zxf openssl-1.1.1s.tar.gz
cd openssl-1.1.1s
./config --prefix=/opt/openssl --openssldir=/opt/openssl/openssl no-zlib
make -j 8 && make install

添加到动态库

echo "/opt/openssl/lib" >> /etc/ld.so.conf
ldconfig -v

编译Python3.10.7源码

使用华为云镜像站下载Python3.10.7源码

wget https://mirrors.huaweicloud.com/python/3.10.7/Python-3.10.7.tgz

修改启动SSL功能

tar -zxf Python-3.10.7.tgz
cd Python-3.10.7
./configure --enable-optimizations --with-openssl=/opt/openssl --with-openssl-rpath=auto --prefix=/usr/local/python3/

进行编译安装

make && make install
echo "export PATH=/usr/local/python3/bin:$PATH" >> /etc/profile
source /etc/profile

一键式脚本

#!/bin/bash
yum install -y epel-release
yum install -y gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel wget
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=/opt/openssl --openssldir=/opt/openssl/openssl no-zlib
make -j 8 && make install
echo "/opt/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
cd ..
wget https://mirrors.huaweicloud.com/python/3.10.7/Python-3.10.7.tgz  --no-check-certificate
tar -zxf Python-3.10.7.tgz
cd Python-3.10.7
./configure --enable-optimizations --with-openssl=/opt/openssl --with-openssl-rpath=auto --prefix=/usr/local/python3/
make -j 8 && make install
echo "export PATH=/usr/local/python3/bin:$PATH" >> /etc/profile
source /etc/profile
cd ..
rm -rf openssl-1.1.1s* Python-3.10.7*

你可能感兴趣的:(Python,centos,ssl,pip,python)