[英]How do I get the SSL module when building python from source on Windows?
[英]Building Python and OpenSSL from source, but ssl module fails
我正在嘗試從容器中的源代碼構建 Python 和 OpenSSL。 兩者似乎都正確構建,但 Python 沒有成功創建_ssl
模塊。
我在網上找到了一些指南,說要取消注釋和 Python- 3.XX/Modules/Setup
,並將--openssldir=/usr/local/ssl
標志添加到 OpenSSL 的./configure
步驟。 我在我的 dockerfile 中做這些。 這導致在 Python 的./configure
輸出期間,我看到以下行。
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
但是我收到以下錯誤:
[91m*** WARNING: renaming "_ssl" since importing it failed: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by build/lib.linux-x86_64-3.8/_ssl.cpython-38-x86_64-linux-gnu.so)
[0m[91m*** WARNING: renaming "_hashlib" since importing it failed: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by build/lib.linux-x86_64-3.8/_hashlib.cpython-38-x86_64-linux-gnu.so)
[0m
Python build finished successfully!
...
Following modules built successfully but were removed because they could not be imported:
_hashlib _ssl
Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
如果./configure
找到X509...
,為什么我仍然收到 hashlib 和 ssl 錯誤?
完整的 Dockerfile,FWIW:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y apt-utils gcc make zlib1g-dev \
build-essential libffi-dev checkinstall libsqlite3-dev
RUN wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz && \
tar xzf openssl-1.1.1d.tar.gz && \
cd openssl-1.1.1d && \
./config -Wl,--enable-new-dtags,-rpath,'$(LIBRPATH)' --prefix=/usr/local/ssl --openssldir=/usr/local/ssl && \
make && \
make test && \
make install
RUN wget -q https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz && \
tar -xzf Python-3.8.2.tgz && \
cd Python-3.8.2 && \
./configure && \
make && \
make install
USER jenkins
我認為 Jenkins Image 安裝了一些不是 1.1.1 的 openssl 版本,因此你在 libssl 中找到了 X509... 但無法構建。
關於上述配置選項,您可以使用 bash 作為 CMD 啟動容器,將容器內的配置復制到鏡像所在的機器上,編輯 ist 並將您的配置版本烘焙到鏡像中。
Following modules built successfully but were removed because they could not be imported: _hashlib _ssl Could not build the ssl module! Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host(). LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381
從源代碼構建 openssl 時,這似乎是安裝問題。 對於_ssl
模塊上的構建失敗,在使用腳本./configure
配置 Python 時嘗試額外的選項,如--with-openssl
、 CFLAGS
和LDFLAGS
,例如
./configure --with-openssl=/PATH/TO/YOUR/OPENSSL_INSTALL_FOLDER/ \
--enable-optimizations \
--with-ssl-default-suites=openssl \
CFLAGS="-I/PATH/TO/YOUR/OPENSSL_INSTALL_FODLER/include" \
LDFLAGS="-L/PATH/TO/YOUR/OPENSSL_INSTALL_FODLER/"
也試試這個命令openssl version
,如果它報告這樣的錯誤:
/usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found
這意味着您的 openssl 庫存在鏈接問題,我不確定您使用的是 Linux 還是其他系統,但對於 Linux 系統,您可以手動修改 openssl 庫的鏈接以解決問題,如我的回答中所述在這里。
參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.