5
1

More than 1 year has passed since last update.

pip/pipenvのSSLエラーが出てハマりまくった。

Posted at

昔、プロキシ環境下で、pip/pipenvにハマったので、備忘録として解決できた方法をまとめました。

今回発生したエラー内容

pipもしくはpipenvを実行すると、以下のエラー内容が表示された。

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)'))': 
)'))': 
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)'))': 
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)'))': 
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)'))': 
Could not fetch URL https://pypi.org/simple/pysimplegui/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)'))) - skipping
ERROR: Could not find a version that satisfies the requirement 
ERROR: No matching distribution found for

プロキシが通っているか確認する。

上記のエラー内容は、大抵の場合、プロキシが通っていない可能性があるので、プロキシを通してやる。
Macでzshを使っている人

zsh
export HTTP_PROXY=http://xxxxxx.xx.xx:◯◯◯◯
export HTTPS_PROXY=https://xxxxxx.xx.xx:◯◯◯◯

Windowsユーザー

Windows
set HTTP_PROXY=http://xxxxxx.xx.xx:◯◯◯◯
set HTTPS_PROXY=https://xxxxxx.xx.xx:◯◯◯◯

この状態で、一度pip insatllを実行してみる。
これでコマンドが正しく実行できればOK。私は、なぜか正しくインストールがされなかったので、次の方法を試した。

pipのオプション--trust-hostをつける

以下の記事を参考に、オプションをつけて実行してみた。

参考サイト : <pip, Python> SSLerrorしても、無理やりインストールする。

ちなみに、信頼するサイトは、以下のPyPIのサイトがいいらしい。

参考サイト : pypi.org

python
pip install --trust-host='https://pypi.org/' install <pakage name>

pipのバージョンを上げる

上記の手段でもできない場合、pipをアップデートする必要がある。

python
pip install -U pip

どうやらSSL周りのエラー内容はpipとPythonのバージョンがあって、発生しているという人もいるらしい。
(長いことPythonを使っていないくて、久々にpipを使ってパッケージをインストールした人は、SSLエラーが出ている。)

私はこれをやったけど、pipのSSLエラーが消えることはなかった。

最終的な解決方法

どうにも解決できず、以下のコマンドを実行すると、pipが正常に動作した。

pip
python3 -m pip install <pakage name>

pipenvを使っている方は、以下のコマンド。

pip
python3 -m pipenv install <package name>

まとめ

私の確認ミスで、かなり時間を取られてしまった。。。
でもなんとかプロキシ環境下でpipが使えたので、良かった。

5
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
5
1