下载源代码

wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz

目录准备

mkdir -p /usr/local/python3.8.2
ln -s /usr/local/python3.8.2 /usr/local/python

解决pip is configured with locations that require TLS/SSL问题

安装依赖

    yum install  gcc libffi-devel zlib* openssl-devel

系统版本centos6.x,其中openssl的版本为OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3。yum 安装的openssl 版本都比较低。

升级openssl

  • 下载
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -zxvf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a
  • 编译安装
./config --prefix=/usr/local/openssl no-zlib #不需要zlib
make
make install
  • 备份原配置
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak
  • 新版配置
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
  • 修改系统配置
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
  • 使修改后的/etc/ld.so.conf生效
ldconfig -v
  • 查看openssl版本
openssl version

编译安装Python

./configure --prefix=/usr/local/python3.8.2  --with-openssl=/usr/local/openssl
make && make install

测试ssl模块成功

[root@localhost python3.8.2]# pip list
Package Version
---------------- ----------
appdirs 1.4.3
certifi 2019.11.28
distlib 0.3.0
filelock 3.0.12
pip 19.2.3
pipenv 2018.11.26
setuptools 41.2.0
six 1.14.0
virtualenv 20.0.7
virtualenv-clone 0.5.3
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@localhost python3.8.2]# python
Python 3.8.2 (default, Mar 2 2020, 06:30:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>