通过 python virtualenvwrapper 链接到 brew openssl

Linking to brew openssl via python virtualenvwrapper

运行 openssl version returns OS El Capitan 上的标准 openssl,/usr/bin/openssl 中的 OpenSSL 0.9.8zh

我已经通过 brew brew install openssl 安装了最新的版本。各种 post/articles 建议手动符号链接到 /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, 在 vi​​rtualenv 的内部和外部并且 运行 import ssl ssl.OPENSSL_VERSION 它返回系统版本。

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

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

这对我有用

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

当我需要比我的 MacOS 上安装的默认版本 python 附带的更新版本的 openssl 时,我遇到了这个问题(我是 运行 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

感谢 and this post 帮助我来到这里。