Python × 業務効率化 メモ

Python初心者による業務効率化・RPA関連の学習メモ / 資格勉強の記録

【Python3】Windows で pip install がエラーになった時に解決する方法

せっかく python をインストールしたので、色んな便利パッケージを pip でインストールしたい。
けど色々なエラーに阻まれて躓いたので、解決方法をメモしておく。

プロキシエラー

pandas を pip install しようとしたらエラーになった。

C:\Users\xxx>pip install pandas
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000021FE88B6510>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))': /simple/pandas/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000021FE80CE2A0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))': /simple/pandas/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000021FE88B7110>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))': /simple/pandas/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000021FE88B75F0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))': /simple/pandas/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000021FE88B7770>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))': /simple/pandas/
ERROR: Could not find a version that satisfies the requirement pandas (from versions: none)
ERROR: No matching distribution found for pandas

解決方法

設定 > ネットワークとインターネット > プロキシで、自動プロキシの「設定を自動的に検出する」をオンにする。


なお、手動プロキシを使う場合は環境変数(HTTP_PROXY, HTTPS_PROXY)を設定すれば通るかも(試していない)。
調べたら下記の記事がヒットしたので、手動プロキシでエラーが出た場合は参考にしたい。

Qiita - 【備忘録】pipでプロキシを突破できなくて詰まった話

※ユーザーID / パスワードがある場合

http://{ユーザーID}:{パスワード}@{プロキシサーバー}:{ポート番号}

※ユーザーID / パスワードがない場合

http://{プロキシサーバー}:{ポート番号}

SSL認証エラー

以前 pypdf を pip install した時に引っかかったエラー。
エラー時のコマンドラインは保存し忘れたのだが、備忘のためその時の対処法を記載する。

解決方法

自動プロキシ下で解決。

C:\Users\xxx\AppData\Roaming\pip フォルダを作成して直下に pip.ini ファイル(pipの設定ファイル)を新規作成した。
※新規のテキストファイルを作成して、ファイル名変更の際に拡張子も変えればOK。

pip.ini には下記を記載する。

[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org

下記の記事も参照。
Qiita - WindowsでPIP Install するとSSLエラーになるのを解消する。