系统环境:Ubuntu 16.04
编译过程:
sudo apt -y build-dep python3.5
pushd /usr/local/src
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar xzf Python-3.7.3.tgz && pushd Python-3.7.3
./configure --prefix=/usr/local/python37 --enable-shared --enable-optimization --enable-ipv6 --with-pydebug --with-assertions --with-lto
make
得到如下输出:
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 动态库版本过低,但是事实上,ubuntu 16.04 自带 OpenSSL 版本为 1.0.2g ,理论上来说应该满足 Python 的需求,也可以确认:
$ openssl version
OpenSSL 1.0.2g 1 Mar 2016
$ apt -y install libssl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl-dev is already the newest version (1.0.2g-1ubuntu4.15).
通过搜索后我在StackOverflow上得到的答案是:
# OpenSSL 1.0.1g
./config shared --prefix=/my/path --openssldir=/my/path/openssl
make
make install
# Python 3.4
export LDFLAGS="-L/my/path/lib/ -L/my/path/lib64/"
export LD_LIBRARY_PATH="/my/path/lib/:/my/path/lib64/"
export CPPFLAGS="-I/my/path/include -I/my/path/include/openssl"
./configure --prefix=/my/path/
make
make install
现在问题如下:
- 为什么系统 Libssl 版本为 1.0.2g 的情况下,Python 编译过程仍有 OpenSSL 版本过低的输出从而无法编译 ssl 库?
- 查阅 Python 的
./configure --help可以看到有一个--with-openssl参数,但我下载 openssl-1.1.1c 源码包后添加该参数生成 Makefile 并进行编译后仍然得到 OpenSSL 版本过低的输出。那么这个--with-openssl参数有何作用?很多其他的程序如 Nginx 通过--with-openssl参数是可以指定静态编译的 OpenSSL 版本的。
感谢指点!