python3.10.5安装时openssl安装失败的问题

初始问题:编译安装python后执行pip list 报错

[root@VM-0-6-centos Python-3.10.5]# pip3 list
Package    Version
---------- -------
pip        22.0.4
setuptools 58.1.0
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
[root@VM-0-6-centos Python-3.10.5]# 

解决办法:
参考链接更新openssl版本:https://blog.csdn.net/tfstone/article/details/109223506,更新版本至3.0.3

更新后,问题依旧存在,检查编译过程,发现编译失败的问题

building '_ssl' extension
gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I./Include -I/usr/local/python/python3_10_5/include -I. -I/usr/local/include -I/data/python/Python-3.10.5/Include -I/data/python/Python-3.10.5 -c /data/python/Python-3.10.5/Modules/_ssl.c -o build/temp.linux-x86_64-3.10/data/python/Python-3.10.5/Modules/_ssl.o
gcc -pthread -shared build/temp.linux-x86_64-3.10/data/python/Python-3.10.5/Modules/_ssl.o -L/usr/local/python/python3_10_5/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-3.10/_ssl.cpython-310-x86_64-linux-gnu.so
building '_hashlib' extension
gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I./Include -I/usr/local/python/python3_10_5/include -I. -I/usr/local/include -I/data/python/Python-3.10.5/Include -I/data/python/Python-3.10.5 -c /data/python/Python-3.10.5/Modules/_hashopenssl.c -o build/temp.linux-x86_64-3.10/data/python/Python-3.10.5/Modules/_hashopenssl.o
gcc -pthread -shared build/temp.linux-x86_64-3.10/data/python/Python-3.10.5/Modules/_hashopenssl.o -L/usr/local/python/python3_10_5/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-3.10/_hashlib.cpython-310-x86_64-linux-gnu.so
*** WARNING: renaming "_ssl" since importing it failed: /data/python/Python-3.10.5/build/lib.linux-x86_64-3.10/_ssl.cpython-310-x86_64-linux-gnu.so: undefined symbol: OPENSSL_sk_num
*** WARNING: renaming "_hashlib" since importing it failed: /data/python/Python-3.10.5/build/lib.linux-x86_64-3.10/_hashlib.cpython-310-x86_64-linux-gnu.so: undefined symbol: EVP_MD_get_type

The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time               


Following modules built successfully but were removed because they could not be imported:
_hashlib              _ssl                                     


Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer

根据报错信息,需要 1.1.1版本以上的openssl,显然条件已经满足,那么应该是旧环境未清理干净所致,严格按照流程重新安装编译

python3.10.5安装时openssl安装失败的问题_第1张图片

最重要是第10步,指定编译依赖库为新版本openssl相关依赖,这里的路径需要根据安装目录灵活配置,例如:

 export LD_LIBRARY_PATH=/usr/local/openssl/lib64:$LD_LIBRARY_PATH

你可能感兴趣的:(linux,python,centos)