文章目录
Python3 默认不支持OpenSSL 1.1.1+以下版本,如果OpenSSL版本过低会提示以下报错ImportError: urllib3 v2 only supports OpenSSL 1.1.1+, currently the ‘ssl‘ module is compiled with ‘O
本次离线安装同时解决Python3依赖OpenSSL版本问题
编译安装OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -xzvf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a
./config --prefix=/usr/local/openssl-1.1.1a
make
make install
添加ld.so.conf
echo "/usr/local/openssl-1.1.1a/lib/" >> /etc/ld.so.conf
ldconfig
不需要替换OpenSSL,直接在Python包中引用即可
[root@kafka-manager bin]# cd /usr/local/openssl-1.1.1a/bin
[root@kafka-manager bin]# ./openssl version
OpenSSL 1.1.1a 20 Nov 2018 (Library: OpenSSL 1.1.1k FIPS 25 Mar 2021)
编译Python
编译Python依赖zlib-devel
,需要自行提前本地yum安装
yum install zlib-devel
下载并编译Python3
wget https://www.python.org/ftp/python/3.8.9/Python-3.8.9.tgz
tar xf Python-3.8.9.tgz
cd Python-3.8.9
./configure --prefix=/opt/python3.8 --with-openssl=/usr/local/openssl-1.1.1a
make && make install
验证服务
验证Python3是否正常
[root@kafka-manager python3.8]# /opt/python3.8/bin/python3 -V
Python 3.8.9
验证Pip3是否正常
[root@kafka-manager python3.8]# /opt/python3.8/bin/pip3 -V
pip 20.2.3 from /opt/python3.8/lib/python3.8/site-packages/pip (python 3.8)
离线安装requests
我们找台有外网的机器,提前下载依赖包
/opt/python3.8/bin/pip3 download -d packages requests
在当前目录会生成package目录
[root@kafka-manager python3.8]# cd packages/
[root@kafka-manager packages]# ls
certifi-2025.1.31-py3-none-any.whl idna-3.10-py3-none-any.whl urllib3-1.26.20-py2.py3-none-any.whl
charset_normalizer-2.0.12-py3-none-any.whl requests-2.27.1-py2.py3-none-any.whl
导入package包,进入package目录,导入离线包
[root@kafka-manager packages]# /opt/python3.8/bin/pip3 install *.whl
Processing ./certifi-2025.1.31-py3-none-any.whl
Processing ./charset_normalizer-3.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Processing ./idna-3.10-py3-none-any.whl
Processing ./requests-2.32.3-py3-none-any.whl
Processing ./urllib3-2.2.3-py3-none-any.whl
Installing collected packages: certifi, charset-normalizer, idna, urllib3, requests
Successfully installed certifi-2025.1.31 charset-normalizer-3.4.1 idna-3.10 requests-2.32.3 urllib3-2.2.3
查看现有包
[root@kafka-manager packages]# /opt/python3.8/bin/pip3 list
Package Version
------------------ ---------
certifi 2025.1.31
charset-normalizer 3.4.1
idna 3.10
jsons 1.6.3
pip 20.2.3
requests 2.32.3
setuptools 49.2.1
typish 1.9.3
urllib3 2.2.3