python - 构建 Python 3.7.1 - SSL 模块失败

标签 python python-3.x ssl openssl

从源代码构建 Python 3.7 遇到以下错误:

Failed to build these modules:
_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

我尝试了很多来自其他 stackoverflow 问题的解决方法,但没有用。我从源代码构建最新的 OpenSSL 和 LibreSSL。 OpenSSL 路径为:“/usr/local/ssl”,版本为 OpenSSL 1.0.2p。

./configure --with-openssl=/usr/local/ssl/
(./configure CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib")
make 
make altinstall

我的系统: Ubuntu 12.04.5 长期支持版

有什么想法吗?

最佳答案

因为 this blog.,我在 3 天后解决了它使用 python 3.7.4 openssl 1.1.0 centOS 6。

这里是总结:

首先,一些先决条件:

sudo apt-get install build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

如果使用 centos linux,请使用 yum 而不是 apt-get。

安装 ssl 1.0.2 或更高版本。

    cd /usr/src
    curl https://www.openssl.org/source/openssl-1.0.2o.tar.gz | tar xz
    cd openssl-1.0.2o
    ./config shared --prefix=/usr/local/
    sudo make
    sudo make install

我们需要将/usr/src/openssl-1.0.2o 传递到 Python 配置脚本中。

mkdir lib
cp ./*.{so,so.1.0.0,a,pc} ./lib

现在继续安装 Python:

    cd /usr/src
    sudo wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
    sudo tar xzf Python-3.7.0.tgz
    cd Python-3.7.0
    ./configure --with-openssl=/usr/src/openssl-1.0.2o --enable-optimizations
    sudo make
    sudo make altinstall

要测试它,运行 python3.7 并输入:

import ssl
ssl.OPENSSL_VERSION

希望对您有所帮助!

关于python - 构建 Python 3.7.1 - SSL 模块失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53543477/

相关文章:

apache - chrome 不信任 https 并显示 ERR_SSL_SERVER_CERT_BAD_FORMAT

python - 从大量条目创建可迭代列表

Python BeautifulSoup 从保存的 HTML 网页中提取表格

使用信任库的java ssl连接

python - 将执行顺序与打印函数调用作为函数参数混淆

python-3.x - Python请求: UnicodeEncodeError: 'charmap' codec can't encode character

tomcat - 在 ubuntu 上使用 APR 库配置带有 SSL 证书的 tomcat 时出错

python - pop() 函数在 for 循环中无法正常运行

python - 是否可以用 if 语句编写单行返回语句?

python - 排除 Python 键入注释中的类型