python - 如何使用 SSL 在 RHEL 上编译 python3?无法导入 SSL

标签 python ssl openssl redhat

我正在尝试在 RHEL 上编译 python,因为我当前的 python 使用的是旧的 1.0.2k ssl 版本。

(test_env) [brad@reason tlscheck]$ python3 --version
Python 3.9.3
(test_env) [brad@reason tlscheck]$ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2k-fips  26 Jan 2017
(test_env) [brad@reason tlscheck]$ openssl version
OpenSSL 1.1.1l  24 Aug 2021
我认为问题是当我编译 3.9.3 时,我没有更新我的 OpenSSL 版本。我已经更新了我的 OpenSSL 并且需要将它与 python 一起使用。所以我下载了最新的python 3.10,但是在make阶段我得到一个错误,它不会用ssl。我以下消息:
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
这是尝试编译的完整日志:
https://pastebin.com/36EntpFz
当我使用@tony-yip 提到的配置选项时,我在配置中得到以下信息。
checking for openssl/ssl.h in /etc/ssl... no
checking whether compiling and linking against OpenSSL works... no
我正在确定我的 openssl 位置:
[brad@reason Python-3.10.0]$ openssl version -d
OPENSSLDIR: "/etc/ssl"
要配置,我正在使用:
./configure --with-openssl="/etc/ssl"
当我查找 ssl.h 时,我在 /usr/include/openssl 中找到它.所以我将此目录链接到 /etc/ssl 中的 lib ,但这没有帮助。
[brad@reason Python-3.10.0]$ ls -l /etc/ssl
total 40
lrwxrwxrwx 1 root root    16 Jul 16  2020 certs -> ../pki/tls/certs
-rw-r--r-- 1 root root   412 Oct 12 02:53 ct_log_list.cnf
-rw-r--r-- 1 root root   412 Oct 12 02:53 ct_log_list.cnf.dist
lrwxrwxrwx 1 root root    20 Oct 18 10:22 lib -> /usr/include/openssl
drwxr-xr-x 2 root root  4096 Oct 12 02:53 misc
-rw-r--r-- 1 root root 10909 Oct 12 02:53 openssl.cnf
-rw-r--r-- 1 root root 10909 Oct 12 02:53 openssl.cnf.dist
drwxr-xr-x 2 root root  4096 Oct 12 02:53 private
[brad@reason Python-3.10.0]$ sudo find / -name ssl.h | grep include
find: ‘/tmp/.mount_jetbraAJFEnl’: Permission denied
/home/brad/Downloads/freerdp-2.0.0-rc4/winpr/include/winpr/ssl.h
/home/brad/Downloads/FreeRDP/winpr/include/winpr/ssl.h
/home/brad/Development/tlscheck/openssl-1.1.1l/include/openssl/ssl.h
/usr/include/openssl/ssl.h
/var/lib/docker/overlay2/23e6f3c164ec8939352891c99393669df4ed6e66da1e04ce84616073f08c6051/diff/usr/include/openssl/ssl.h
/var/lib/flatpak/runtime/org.freedesktop.Sdk/x86_64/18.08/c8075e929daaffcbe5c78c9e87c0f0463d75e90d2b59c92355fa486e79c7d0e3/files/include/nss/ssl.h
/var/lib/flatpak/runtime/org.freedesktop.Sdk/x86_64/18.08/c8075e929daaffcbe5c78c9e87c0f0463d75e90d2b59c92355fa486e79c7d0e3/files/include/openssl/ssl.h
find: ‘/run/user/1000/gvfs’: Permission denied
这可能是无关信息,但我的 libssl.so 在这里:
[brad@reason Python-3.10.0]$ ls /usr/lib64 | grep ssl
libevent_openssl-2.0.so.5
libevent_openssl-2.0.so.5.1.9
libssl3.so
libssl.so
libssl.so.10
libssl.so.1.0.2k
openssl
关于为什么 make 不能包含 ssl 的任何想法,请告诉我。谢谢。

最佳答案

有一个非常相似的问题,openssl 无法正常工作,并且在 centos 7 上使用 python 3.10 给出了相同的错误。
下载openssl解包然后去那个目录

./config --prefix=/usr/local/custom-openssl --openssldir=/etc/ssl
make -j1 depend
make -j8
make install_sw
然后去python源码解压,在目录下运行
./configure -C --with-openssl=/usr/local/custom-openssl --with-openssl-rpath=auto --prefix=/usr/local/python-3.version
make -j8
make altinstall
另请参阅 https://docs.python.org/3/using/unix.html 上的自定义 OpenSSL .

关于python - 如何使用 SSL 在 RHEL 上编译 python3?无法导入 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69539286/

相关文章:

python-3.x - MacOS 上的 pip3 : SSL error while installing virtualenv

amazon-web-services - API Gateway 和 Elastic Beanstalk 之间是否需要 HTTPS?

curl - 当 curl 或 file_get_contents 请求 https url 时,php-fpm 崩溃

python - 为什么在我给出位置参数时 lambda 返回 "<lambda>() takes 0 positional arguments but 1 was given"?

python - 在 python 中使用命令行参数标志的正确方法

python - Pytorch 保存模型 UserWarning : Couldn't retrieve source code for container of type Network

authentication - 针对 API 服务器的 kubernetes 身份验证

c - OpenSSL ASN1_item_ex_d2i 内存泄漏

node.js - Node TLS 套接字 : DEPTH_ZERO_SELF_SIGNED_CERT error

python - 如何在 "Next"按钮之后使用 scrapy 获取 Amazon.com 链接?