pip install が「SSL: CERTIFICATE_ VERIFY_ FAILED」でインストールできない
SSL: CERTIFICATE_VERIFY_FAILED は、pip が接続先の証明書を検証できないと出る。
社内 CA を --cert や pip config で渡すか、pip を 24.2 以降に上げれば直る。
公開: 更新:
pip install --disable-pip-version-check --retries 0 --index-url https://localhost:8443/simple/ sampleproject Looking in indexes: https://localhost:8443/simple/ Could not fetch URL https://localhost:8443/simple/sampleproject/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='localhost', port=8443): Max retries exceeded with url: /simple/sampleproject/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1010)'))) - skipping ERROR: Could not find a version that satisfies the requirement sampleproject (from versions: none) ERROR: No matching distribution found for sampleproject
2026-08-13 に python:3.12 で実際に打って取った出力。検証環境の詳細
要約
pip install が SSL: CERTIFICATE_VERIFY_FAILED で止まるのは、pip がパッケージインデックス(既定は pypi.org / files.pythonhosted.org)への HTTPS 接続で、相手の証明書を信頼できる CA までたどれなかったためである。
pip が証明書の検証に使うのは、pip 自身に同梱された certifi(pip._vendor.certifi)と、pip 24.2 以降かつ Python 3.10 以上なら OS の証明書ストアである(HTTPS Certificates - pip documentation(新しいタブで開く))。
環境に別途入っている certifi パッケージは pip の検証に使われないので、pip install --upgrade certifi では pip のこのエラーは直らない。
直すべきなのは「社内 CA を pip に渡す」か「pip を新しくする」のどちらかである。
--trusted-host で検証を切ると中間者攻撃を防げなくなるので、恒久策にはしない。
実行例
python:3.12 から自己署名証明書のインデックスへ繋ぐと、まず [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate が出て取得そのものが打ち切られる。
社内 CA を渡した後は同じコマンドでも証明書の検証エラーが消え、テスト用インデックスに該当パッケージが無いという別の理由での失敗に変わるため、証明書側だけが解消したことが読み取れる。pip config set global.cert を使うと、その CA のパスが ~/.config/pip/pip.conf に保存されて以降の実行にも引き継がれる。
$ pip install --disable-pip-version-check --retries 0 --index-url https://localhost:8443/simple/ sampleproject
Looking in indexes: https://localhost:8443/simple/
Could not fetch URL https://localhost:8443/simple/sampleproject/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='localhost', port=8443): Max retries exceeded with url: /simple/sampleproject/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1010)'))) - skipping
ERROR: Could not find a version that satisfies the requirement sampleproject (from versions: none)
ERROR: No matching distribution found for sampleproject
$ echo $?
1$ pip install --disable-pip-version-check --retries 0 --index-url https://localhost:8443/simple/ sampleproject
Looking in indexes: https://localhost:8443/simple/
ERROR: Could not find a version that satisfies the requirement sampleproject (from versions: none)
ERROR: No matching distribution found for sampleproject
$ echo $?
1$ pip config set global.cert /tmp/tmp.Uxm4YxxWIQ/corp-ca.pem
Writing to /root/.config/pip/pip.conf$ pip config list
global.cert='/tmp/tmp.Uxm4YxxWIQ/corp-ca.pem'$ pip install --disable-pip-version-check --retries 0 --index-url https://localhost:8443/simple/ sampleproject
Looking in indexes: https://localhost:8443/simple/
ERROR: Could not find a version that satisfies the requirement sampleproject (from versions: none)
ERROR: No matching distribution found for sampleproject
$ echo $?
1— 2026-08-13 時点の出力
検証環境2026-08-13 検証
- 検証日
- 実行環境
python:3.12
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. 社内 CA を pip に渡す
SSL 検査環境や社内ミラーでは、配布されている社内 CA の証明書(PEM)を --cert で渡す。
pip install --cert /path/to/corp-ca.pem requests環境変数でも渡せる。PIP_CERT は --cert と同じ設定で、REQUESTS_CA_BUNDLE も pip の証明書バンドルの指定に使える(HTTPS Certificates(新しいタブで開く))。
export PIP_CERT=/etc/ssl/certs/corp-ca.pem
pip install <pkg>2. pip config で恒久化する
毎回指定するのが手間なら、pip の設定ファイルに書く。
pip config set global.cert /etc/ssl/certs/corp-ca.pemLinux ではユーザー単位の ~/.config/pip/pip.conf に書き込まれ、以降の pip install に引き継がれる(Windows では pip.ini)。
設定ファイルの場所は Configuration(新しいタブで開く) にある。
3. pip を更新して OS の証明書ストアを使わせる
pip 24.2 以降は、Python 3.10 以上であれば同梱の certifi に加えて OS の証明書ストアも使って検証する(Changelog 24.2(新しいタブで開く))。
社内 CA が IT 部門によって OS の証明書ストアに配布済みなら、pip を更新するだけで通ることがある。
python -m pip install --upgrade pippip 22.2〜24.1 では、--use-feature=truststore を付けたときだけ OS の証明書ストアを使う。
逆に 24.2 以降で以前の挙動(certifi だけで検証)に戻すには --use-deprecated=legacy-certs を付ける。
pip の更新自体が同じエラーで失敗するときは、先に 1 の --cert を付けて更新する。
4. 暫定回避(信頼ホスト)
急ぐときだけ --trusted-host で検証を回避できるが、中間者攻撃を防げなくなるので恒久利用は避ける。
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org requestsあわせて、システムの日付と時刻がずれていないかも確認する。
pip ではなく自分のコードで出る場合
requests を使う自分のコードで同じエラーが出るなら、話が変わる。
requests は環境に入っている certifi パッケージの証明書を使うので(Requests: CA Certificates(新しいタブで開く))、python -m pip install --upgrade certifi が効くのはこちらである。
社内 CA を使わせるなら REQUESTS_CA_BUNDLE を設定する。
macOS で python.org のインストーラを使った場合は、/Applications/Python 3.x/Install Certificates.command がその Python 用のルート証明書を入れる(Using Python on macOS(新しいタブで開く))。
よくある原因
- 社内ネットワークの SSL 検査プロキシが通信を復号し、社内 CA で署名した証明書に差し替えている。
certifi にはその CA が無いので、検証が通らない。 - 社内 PyPI / devpi が、自己署名や社内 CA の証明書で HTTPS を提供している。
- pip が古い。
pip は certifi を同梱しており、リリースごとに更新している(Changelog(新しいタブで開く))。
24.2 より前の pip は既定で OS の証明書ストアを使わないので、OS には入っている社内 CA も信頼しない。 - 端末の時計がずれている。
日時が大きく狂っていると、証明書の有効期間チェックに失敗する。