python3.6.5 SSL问题解决:pip is configured with locations that require TLS/SSL, however the ssl module in

环境和背景介绍:
MacOS Catalina 10.15.3
Homebrew 安装了如下python版本
python 2.7.17
python 3.7.6_1
python 3.6.5_1
python3.6/3.7通过brew switch python 3.6.5_1brew switch python 3.7.6_1切换。

问题描述:
在python3版本是 3.6.5的时候,pip3安装提示:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

我翻阅了至少30个帖子或者博文包括stackoverflow上面的很多类似帖子,没有一个解决了实际问题。后来想了一下,试试重新安装pip?然后wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py的时候提示:

yld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/bin/wget
  Reason: image not found

然后为了解决这个问题搜到一篇文章:
MAC dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
里面提到一个方法:

brew switch openssl 1.0.2s

然后我终于恍然大悟,这才是症结所在啊~~~~~因为默认安装的是openssl1.1,死活找不到切换的方法,网上各种建立软连接的方式不好用。

所以我只要输入brew switch openssl 1.0.2t,就完美解决了前文所述的问题。

我的版本是 1.0.2t,你自己的版本可以通过如下方式看到:

ls /usr/local/Cellar/openssl/

如果没有,可以通过如下命令安装:

brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

相关博文:

  1. brew安装指定版本的Python / 解决Macbook上Python3.7版本不能安装Tensorflow的问题 这篇文章可以告诉你如何通过git log 来安装旧版本的python。
  2. Installing older versions of a Homebrew formula (2018 edition) | Dane Powell 这篇文章教你如果从网上的页面查找commit来安装旧版本的python。
  3. homebrew - How to install specific version of python on OS X - Ask Different 这个帖子教你如何安装第三方的python包(比如有3.6.10的版本),但是可能会搞乱你的homebrew python3环境。
  4. Homebrew: Rollback from Python 3.7 to Python 3.6.5.x? - Ask Different 这个帖子教你如何从使用brew extract从本地的tap安装旧版本的python。
  5. OS X Python 3.7 openssl 终极冲突解决大法(PART 1) 此文思路可参考,但是没有解决我的问题。
  6. OS X Python 3.7 openssl 终极冲突解决大法(PART 2)此文思路可参考,但是没有解决我的问题。
  7. mac上根治SSL的各种报错python3此文思路可参考,但是没有解决我的问题。

Note:值得一提的是brew install--with-brewed-openssl参数会被忽略。所以并不能解决本文的问题。

最后给出homebrew安装 python 3.6.5的方法:

如果遇到443端口错误,把https改为http即可。

brew unlink python3
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

版本切换:

#查看现有版本
brew info python3 
#切换版本(根据上面命令的结果给出的版本而定)
brew switch python 3.7.6_1
brew switch python 3.6.5_1
发布了227 篇原创文章 · 获赞 148 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/toopoo/article/details/104720022