【问题标题】:Compiling Python 2.7.12 with non-system Openssl on Centos 5在 Centos 5 上使用非系统 Openssl 编译 Python 2.7.12
【发布时间】:2016-12-06 10:27:11
【问题描述】:

我目前正在尝试让 Python 2.7.12 在 Centos 5 主机上与 Openssl 1.0.2h 一起编译。

原因是我需要在此主机上运行 Paramiko 2,但它不支持系统提供的 OpenSSL 版本,即 0.9.8e-fips-rhel5 01 Jul 2008。

我在这里找到了一些很棒的提示和技巧,但它似乎不起作用。我现在发布此内容,希望有人能发现我做错了什么/遗漏了什么。

对于 OpenSSL 设置,我完成了以下操作:

OPENSSL_ROOT="$HOME/.build/openssl-1.0.1e"
cd /tmp
curl http://www.openssl.org/source/openssl-1.0.2h.tar.gz | tar zxvf -
cd openssl-1.0.2.h
mkdir -p "$OPENSSL_ROOT"
./config no-hw --prefix="$OPENSSL_ROOT" --openssldir=...
make install

然后由于我不想用 2.7.12 替换系统安装的 Python,我做了以下操作:

首先我将 /usr/local/lib 添加到 /etc/ld.so.conf 并运行 ldconfig。

之后我跑了:

cd /tmp
wget http://python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
tar xf Python-2.7.12.tar.xz
cd Python-2.7.12
./configure CPPFLAGS="-I$OPENSSL_ROOT/include"  LDFLAGS="-L$OPENSSL_ROOT/lib"  --prefix=/usr/local --enable-unicode=ucs4 --enable-shared
make && make altinstall

这是我以为我会针对新版本的 OpenSSL 编译它的时候,但没有,正如您从此处的输出中看到的那样:

[root@an-host openssl-1.0.2h]# python2.7 -c "import ssl; print ssl.OPENSSL_VERSION"
OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

而且我确信我正在运行新编译的版本,因为这在此处得到了回应:

[root@an-host openssl-1.0.2h]# python2.7
Python 2.7.12 (default, Aug  1 2016, 11:46:42) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

我什至已经用 Yum 删除了 openssl-devel,但它似乎仍然不关心/编译 1.0.2h。

目前这让我有点生气,因此非常感谢任何输入/反馈/帮助。

【问题讨论】:

  • 我认为您需要最新版本的 0.98 而不是 1.x。
  • 我不确定我是否在关注你。问题是如何使用已编译到“非默认”目录的“非系统标准”OpenSSL 构建来编译 Python 2.7.12。您是否暗示它不会使用 1.x 编译但会使用 0.98 版本?或者您是在谈论您认为 Paramiko 2 需要什么?
  • 当我最近在 Centos 7 上构建它时,我很确定它需要 0.98x
  • 刚刚看了 paramiko 页面。我错了,别理我。
  • 究竟是什么问题?错误信息或问题在哪里?

标签: python linux compilation openssl centos5


【解决方案1】:

我想我试图复制太可爱的解决方案并混合搭配 - 整理并简化了一点,最终让它发挥作用。

这就是我这次所做的:

下载并安装 OpenSSL

cd /tmp 
curl http://www.openssl.org/source/openssl-1.0.2h.tar.gz | tar zxvf - 
cd openssl-1.0.2.h 
./config shared --prefix=/usr/local/ 
make && make install

设置一些环境变量

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

下载并安装 Python 2.7.12

wget http://python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
tar xf Python-2.7.12.tar.xz
cd Python-2.7.12
./configure --prefix=/usr/local/ --enable-unicode=ucs4 --enable-shared
make && make altinstall

现在它按预期工作,显示较新的 OpenSSL 版本。

[root@an-host Python-2.7.12]# python2.7
Python 2.7.12 (default, Aug  1 2016, 14:48:09) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> print ssl.OPENSSL_VERSION
OpenSSL 1.0.2h  3 May 2016

但是,它仍然没有按预期工作。 :( 运行程序我从 Paramiko 收到以下错误:

RuntimeError: You are linking against OpenSSL 0.9.8, which is no longer support by the OpenSSL project. You need to upgrade to a newer version of OpenSSL.

我找到的解决方案是通过运行卸载并重新安装 Cryptography 的点点滴滴。

pip2.7 uninstall cryptography
pip2.7 install cryptography

毕竟 - 它现在可以工作了。

【讨论】:

    猜你喜欢
    • 2017-12-20
    • 2020-08-25
    • 1970-01-01
    • 2020-06-23
    • 2019-04-25
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多