2018年9月10日月曜日

pip install が使えなくなったので修復方法を模索する

久々に Python へライブラリを追加して遊ぼうと思ったのですが、pip install が一切使用できない事態になっていました……。

スクリーンショットを撮っておけばよかったのですが……。pip install 実行後に「Could not fetch URL」から始まって「There was a problem confirming the ssl certificate」を経由して「Could not find a version that satisfies the requirement 〇〇 (from versions: )」と表示されるような状態になっていました。URLに繋げられなかったのだから、〇〇(インストールしたかったライブラリ)が見つからないのは当然です。

よくある解決方法1

pip のバージョンが古いと install を使えなくなる似た事態になるようです。

Problem Confirming the SSL Certificate - OSX · Issue #5236 · pypa/pip

Pip version: pip 9.0.1 Python version: Python 3.5.2 and Python 2.7.10 installed Operating system: OSX - 10.13.4 Description: I've tried to install Keras (keras.io) and faced with a problem related confirming ssl certificate. What I've ru...

「pip が使えないなら、curl でやってみて」なんて書かれているけれど、今回は curl もダメでした。

curl https://bootstrap.pypa.io/get-pip.py | python3

よくある解決方法2

ひたすら「--trusted-host」オプションを付ける方法で改善するパターンもあるようです。ただし、自分の環境ではコレでも改善できなかった……。

Cannot update or install anything with pip, SSL error

Hi everyone, this is my first time posting on here and I really need help with this problem. I've had Python and pip on my PC since I got it about a year ago and never really used pip that much until recently. I'm working on a project with my friend ...

python -m pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org --upgrade pip

結局、何が悪かったのか?

ウイルス対策ソフトでした。端末にインストールされているカスペルスキー、これのバージョンアップ版がリリースされていたようだったので、入れ替えてみると pip コマンドが元通り使えるようになりました。ウイルス対策ソフトが原因で不通になるとか、“あるある現象”でしたね……。

似た事象で困った場合は、チェックしてみても良いかもしれません。