【问题标题】:Linking to brew openssl via python virtualenvwrapper通过 python virtualenvwrapper 链接到 brew openssl
【发布时间】:2016-08-09 20:18:30
【问题描述】:

运行 openssl version 在 OS El Capitan 上返回标准 openssl,OpenSSL 0.9.8zh in /usr/bin/openssl

我已经通过 brew brew install openssl 安装了最新版本。建议手动链接到/usr/local/bin/openssl 或运行brew link --force openssl 的各种帖子/文章。其他帖子说不要这样做,运行后者也给出了以下警告。

Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

我不确定这意味着什么。 :|

我还成功地符号链接到 brew 版本,所以which openssl 指向/usr/local/bin/openssl 而不是系统/usr/bin/openssl 版本,which openssl 也返回了最新版本,但是当我打开一个 python shell 时,里面在 virtualenv 之外运行 import ssl ssl.OPENSSL_VERSION 它返回了系统版本。

如何强制它在我的 python 代码中使用 brew 版本?

【问题讨论】:

  • 问题是什么?参见 Stack Overflow 上的 Brew refusing to link opensslLink: don't link /usr/local openssl Github 提交。
  • 谢谢 jww,我已经相应地编辑了问题。我已经阅读了这些内容,您是否建议实施 Ben Collins .net 解决方案? sudo install_name_tool -add_rpath... 在 python 环境中我在哪里做这个?
  • 是的,您应该始终在 OS X 系统上使用 OpenSSL 的安装名称。我知道 OpenSSL 1.1.0 使用它们,但我不记得 OpenSSL 1.0.2 和更早版本。不过,这只是成功的一半。另一半是确保 Apache、Python 和 Ruby 等程序针对更新的 OpenSSL 进行编译和链接。为确保在编译时使用正确的库,您必须使用-I-L。为确保运行时链接器使用正确的 OpenSSL 库,使用了安装名称。

标签: python ssl openssl virtualenv homebrew


【解决方案1】:

当我需要更新版本的 openssl 时遇到了这个问题,而不是我的 MacOS 上安装的默认版本的 python(我运行的是 10.12.5)。在我使用virtualenvwrapper 创建的虚拟环境中运行 Django 服务器时,出现以下错误:

我通过运行查看了我链接的 openssl 版本:

$ python -c "import ssl; print ssl.OPENSSL_VERSION"                                                                                                                                                                                                              

OpenSSL 0.9.8zh 14 Jan 2016

这是我为解决此问题所做的:

$ brew update
$ brew install openssl
$ brew install python --with-brewed-openssl # for me this lives in /usr/local/Cellar/python/2.7.13/bin/python

我们将指向virtualenvwrapper 使用此版本的python:

$ mkvirtualenv --python=/usr/local/Cellar/python/2.7.13/bin/python envName

现在让我们检查一下我们的 envname 虚拟环境下的 openssl 版本:

(envName) $ python -c "import ssl; print ssl.OPENSSL_VERSION"                                                                                                                                                                                                              

OpenSSL 1.0.2l  25 May 2017

感谢thisthis 发帖帮助我到达这里。

【讨论】:

  • 这对我来说超级方便!
  • 如果我想让新创建的 Python(使用 virtualenv env )使用新的 OpenSSL 怎么办?
【解决方案2】:

最后我使用brew install python3 --with-brewed-openssl,然后运行brew link python3 将其符号链接到/usr/local/bin/python3,然后使用mkvirtualenv --python=/usr/local/bin/python3 [projectname] 使用酿造的python(使用酿造的openssl),现在当我运行import ssl ssl.OPENSSL_VERSION在我的 virtualenv 中,我指向我酿造的 openssl,我不必触摸我的系统 openssl 或 python。这是一个类似的问题Updating openssl in python 2.7

【讨论】:

    【解决方案3】:

    这对我有用

    brew install python3 --with-brewed-openssl
    brew link --overwrite python3
    

    【讨论】:

      猜你喜欢
      • 2017-12-24
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 2020-10-17
      • 2020-08-05
      • 2013-12-25
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多