关于 Ubuntu 下编译安装 Python 时 OpenSSL 库问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fourstring
V2EX    Python

关于 Ubuntu 下编译安装 Python 时 OpenSSL 库问题

  •  
  •   fourstring 2019 年 5 月 31 日 5061 次点击
    这是一个创建于 2423 天前的主题,其中的信息可能已经有所发展或是发生改变。

    系统环境: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 

    现在问题如下:

    1. 为什么系统 Libssl 版本为 1.0.2g 的情况下,Python 编译过程仍有 OpenSSL 版本过低的输出从而无法编译 ssl 库?
    2. 查阅 Python 的./configure --help可以看到有一个--with-openssl参数,但我下载 openssl-1.1.1c 源码包后添加该参数生成 Makefile 并进行编译后仍然得到 OpenSSL 版本过低的输出。那么这个--with-openssl参数有何作用?很多其他的程序如 Nginx 通过--with-openssl参数是可以指定静态编译的 OpenSSL 版本的。

    感谢指点!

    13 条回复    2019-06-03 09:48:05 +08:00
    ysc3839
        1
    ysc3839  
       2019 年 5 月 31 日 via Android   1
    手动编译是有什么特殊需求吗?不能用 pyenv 这种自动编译的脚本吗?
    fourstring
        2
    fourstring  
    OP
       2019 年 5 月 31 日
    @ysc3839 #1 非常感谢,这个我还真不知道。。。看起来不错
    fourstring
        3
    fourstring  
    OP
       2019 年 5 月 31 日
    @ysc3839 #1 不过我还是想知道这样编译问题在哪里
    0ZXYDDu796nVCFxq
        4
    0ZXYDDu796nVCFxq  
       2019 年 5 月 31 日 via Android   1
    pkg-config --libs libssl 看下链接了哪个库
    可能你系统里有多个库
    fourstring
        5
    fourstring  
    OP
       2019 年 5 月 31 日
    @gstqc #4 输出只有-lssl 这应该是链接的系统 libssl 吧。
    另外执行 dpkg -l | grep libssl 输出如下
    ii libssl-dev:amd64 1.0.2g-1ubuntu4.15 amd64 Secure Sockets Layer toolkit - development files
    ii libssl1.0.0:amd64 1.0.2g-1ubuntu4.15 amd64 Secure Sockets Layer toolkit - shared libraries
    这说明我系统只有一个 libssl 库啊
    0ZXYDDu796nVCFxq
        6
    0ZXYDDu796nVCFxq  
       2019 年 5 月 31 日 via Android   1
    是否安装了 libressl
    fourstring
        7
    fourstring  
    OP
       2019 年 5 月 31 日
    @gstqc #6 并没有
    ysc3839
        9
    ysc3839  
       2019 年 5 月 31 日   1
    @fourstring 我没手动编译过,所以也不知道是什么问题……
    ClericPy
        10
    ClericPy  
       2019 年 6 月 1 日
    3.7 和 3.6 以前的这个依赖不一样了, 既然都选择 Ubuntu 了, 使用
    apt-get install python3.7-dev
    就可以了
    我给阿里云机器升级的 Ubuntu 18 用的这个方法, 反正 python3-dev 是不够用的
    ysc3839
        11
    ysc3839  
       2019 年 6 月 1 日 via Android
    @ClericPy Ubuntu 16.04 官方源里面没有 Python 3.7 吧?不过我印象中有个 ppa 源有的。

    找到了 https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
    fourstring
        12
    fourstring  
    OP
       2019 年 6 月 1 日   1
    @ysc3839 #11 正确的编译方法就是 StackOverflow 上那样编译之后再把编译好的 openssl 的.so 文件加入系统 /etc/ld.so.conf 然后 ldconfig,这个问题即使用 pyenv 也无法避免,它好像不会自动解决 openssl 的依赖问题。现在我就很好奇为什么系统的 openssl 库会被认为版本过低以及那个--with-openssl 参数的作用……
    Kobayashi
        13
    Kobayashi  
       2019 年 6 月 3 日
    @fourstring 用 Vagrant 下的 Ubuntu 16.04 测试了一下,pyenv 安装 Python 3.7.3。没有出现你所说的问题,一切正常。pyenv 编译很简单,只要确保编译依赖安装齐全。https://github.com/pyenv/pyenv/wiki

    vagrant@ubuntu-xenial ~
    which -a openssl
    /usr/bin/openssl

    vagrant@ubuntu-xenial ~
    openssl version
    OpenSSL 1.0.2g 1 Mar 2016

    vagrant@ubuntu-xenial ~
    pyenv which python
    /home/vagrant/.local/share/pyenv/versions/3.7.3/bin/python
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2850 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 12:52 PVG 20:52 LAX 04:52 JFK 07:52
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86