构建Python3.7.1-SSL模块失败

2024-06-01 23:26:08 发布

您现在位置:Python中文网/ 问答频道 /正文

从源代码构建Python3.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

我试过很多其他堆积如山的问题,但都没用。我从源代码构建最新的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 LTS公司

有什么想法吗?


Tags: thebuildsslmake源代码configureusrlocal
3条回答

我在3天后解决了这个问题,只是因为this blog.使用了python 3.7.4openssl 1.1.0centos 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

希望有帮助!

虽然这可能不是最好的答案,但我将分享我是如何解决这个问题的。

  1. 首先,在我的例子中,OpenSSL没有正确构建,因为make test返回了错误(因此Python给出了这个错误)。这是通过安装一个更新版本的Perl,然后再次安装OpenSSL(configure、make等)来解决的。

  2. 使用前使用此命令./configure

    export LD_LIBRARY_PATH=/path/to/openssl/lib:$LD_LIBRARY_PATH

  3. 在configure命令中,包括库:

    LDFLAGS="-L/path/to/openssl/lib" ./configure (all your preferred options) --with-openssl=/path/to/openssl

    显然,configure选项不会将消息传递给需要它的C编译器。

不确定是否同时需要选项2和选项3,但我做到了,而且成功了。

我就是这么做的

brew reinstall openssl

brew unlink openssl && brew link openssl --force

  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

然后下载python tarball并执行以下操作

tar xvf Python-3.7.2.tar
cd Python-3.7.2
  ./configure CPPFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" --prefix=$PWD/Python-3.7.2/mybuild --enable-optimizations

相关问题 更多 >