pip install でSSL関連のエラーが出たらこれを読め!!!


環境

mac OS Catalina
python 3.6.5

状況

pythonをしばらく放置(1年くらい)していたのですが、新しくパッケージをインストールしようと思いpip install <package name>したところこんなエラーに...

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting numpy-stl(今回インストールしようとしたパッケージ名)
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy-stl/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy-stl/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy-stl/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy-stl/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/numpy-stl/
  Could not fetch URL https://pypi.org/simple/numpy-stl/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/numpy-stl/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
  ERROR: Could not find a version that satisfies the requirement numpy-stl (from versions: none)
ERROR: No matching distribution found for numpy-stl
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping

色々調べたところ、解決法として
- pipのアップデート
- pip install時にホストを信頼させるオプションをつける
- curl のアップデート
- pip.conf を作る
等色々あったので全部試しましたが、いずれもうまくいきませんでした。参考
この時点でかなり絶望。。。

解決法

結局pythonのバージョンをあげてpipごと心機一転させてあげることで解決しました。(途中でXcodeのCommandLineToolのアップデートが必要かもしれません。)
僕はpyenvを使っていたので、

pyenv install 3.8.1
pyenv global 3.8.1
pip install (インストールしたいパッケージ)

で無事インストール完了できました!!!

もし同じ悩みで絶望している方がこれで解決できたら嬉しいです。もしよかったらいいね!!してください!