有关python 3.7 pip 出现 TLS/SSL not available

最近重装了macOS,半夜用python3发现这问题,结果弄到两点半。。

起因是brew安装工具是由于依赖关系安装了python3.7,之后在我使用python3.7的pip安装模块时出现问题

明显是SSL模块不可用

那就装呗,but,我几乎试遍网上方法也不管用

查看安装路径

1
2
$ brew --prefix openssl
/usr/local/opt/openssl

尝试带ssl重新编译安装python3

1
2
3
./configure --prefix=/usr/local/python37 --with-openssl=/usr/local/opt/openssl
make
make install

依然是

ModuleNotFoundError: No module named '_ssl'

让 brew 强制链接 openssl 到环境变量

brew link openssl --force

但是 brew 拒绝链接,警告如下:

1
2
3
4
5
6
7
8
9
10
Warning: Refusing to link macOS-provided software: openssl
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

尝试手动创建软连接,通过 brew 安装的 OpenSSL 的头文件位于 /usr/local/Cellar/openssl/1.0.2q/include/openssl 文件夹内,在终端内执行:

ln -s /usr/local/Cellar/openssl/1.0.2q/include/openssl /usr/local/include

又设置环境变量

1
2
$ export CFLAGS="-I/usr/local/opt/openssl/include"
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"

在编译时设置 LDFLAGS 与 CPPFLAGS

1
2
3
./configure CPPFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib"
make
make install

依然无法解决问题

最终想起很久之前python3是用python-3.7.2-macosx10.9 02-30-21-902.pkg这种安装器装的

然后我抱着试试的心态,通过python3的installer安装路径为/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

解决了,WTF

原来是 installer 包含了 private copies of OpenSSL 1.1.0

文章作者: J0k3r
文章链接: http://j0k3r.top/2019/02/17/SslNotAvailable/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 J0k3r's Blog