0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-11-26

要約

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. と出る場合を参考に、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を読んでいたら、

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が環境構築時にその辺いい感じにしてくれるため、構築済みの仮想環境を普通の環境と同様に扱っても上手く行かないよ。ってところでしょうか。

その他

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

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

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?