opensslを再インストールしてもpip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.が直らない

## 要約
pyenv(pyenv-virtualenv)を使っている環境下で、`pip install`時に

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

と表示されてインストールができなかった。

解決策として

- **opensslを再インストール**
- **pyenvのPython環境も再インストール**

を行ったら直った。

## 環境
OS: macOS Catalina
shell: fish
Python: pyenv-virtualenvのPython3.7.3
pip: 19.0.3

## 問題
`pip install requests`を行ったら以下のメッセージが表示されて、インストールできなかった。

```
$ pip install requests
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting requests
  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/requests/
  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/requests/
  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/requests/
  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/requests/
  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/requests/
  Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
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
```

## opensslの再インストール
[pipのインストールで pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. と出る場合](https://qiita.com/drumehiron/items/da79d837ffea3723aafe)を参考に、`openssl`の再インストール

```
brew unlink openssl 
brew reinstall openssl
```

→ 直らなかった。

## opensslのパスを通す
opensslの再インストール時に以下のメッセージが表示されたので、何も考えず`~/.config/fish/config.fish`に追記

```
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'set -g fish_user_paths "/usr/local/opt/openssl@1.1/bin" $fish_user_paths' >> ~/.config/fish/config.fish

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

For pkg-config to find openssl@1.1 you may need to set:
  set -gx PKG_CONFIG_PATH "/usr/local/opt/openssl@1.1/lib/pkgconfig"
```

→ 直らなかった。

## Pythonの環境を変える
[Requests (Caused by SSLError(“Can't connect to HTTPS URL because the SSL module is not available.”) Error in PyCharm requesting website](https://stackoverflow.com/questions/54135206/requests-caused-by-sslerrorcant-connect-to-https-url-because-the-ssl-module)を読んでいたら、

`brew upgrade python3`

とあったので、Pythonをバージョンアップしてみる

```
$ python -V  # => Python 3.7.3
$ pyenv uninstall {pyenv-virtualenvの環境名}
$ pyenv install 3.7.4  # => このバージョンは初インストール
$ pyenv virtualenv 3.7.4 {pyenv-virtualenvの環境名}
```

→ 直った。

## 考察
はっきり説明できる原因はわかりませんでしたが、pyenvが環境構築時にその辺いい感じにしてくれるため、構築済みの仮想環境を普通の環境と同様に扱っても上手く行かないよ。ってところでしょうか。

## その他
記事を書くために似たような事例を調べていたら、結構記事ありました。

ドハマってる時にはたどり着けないのに、解決したあと記事を書こうとすると意外と出てくる。これホントつらい。

## 参考
- [pipのインストールで pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. と出る場合](https://qiita.com/drumehiron/items/da79d837ffea3723aafe)
- [Requests (Caused by SSLError(“Can't connect to HTTPS URL because the SSL module is not available.”) Error in PyCharm requesting website](https://stackoverflow.com/questions/54135206/requests-caused-by-sslerrorcant-connect-to-https-url-because-the-ssl-module)
- [pip installでSSLのエラー](https://note.com/yo16/n/na9ce9a63685a)
- [pip install でSSL証明書関連？のエラー](https://qiita.com/akashixi/items/14d05ddf0a3d1176956c)