You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10安装Python包遇OSError: HTTPSConnectionPool SSL证书验证失败求助

问题描述

在Windows 10系统中执行pip install mkdocs安装mkdocs包时,无论在用户目录还是C:\Windows\system32目录下操作,均出现SSL证书验证失败错误,具体错误信息如下:

C:\Users\BSTC>pip install mkdocs
Collecting mkdocs
  Obtaining dependency information for mkdocs from https://files.pythonhosted.org/packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)'))': /packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)'))': /packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)'))': /packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)'))': /packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)'))': /packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/89/58/aa3301b23966a71d7f8e55233f467b3cec94a651434e9cd9053811342539/mkdocs-1.5.3-py3-none-any.whl.metadata (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1000)')))


[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
解决方案

方法1:临时跳过SSL验证

执行安装命令时添加--trusted-host参数,指定PyPI相关域名:

pip install mkdocs --trusted-host pypi.org --trusted-host files.pythonhosted.org

若需同时升级pip,使用同样参数:

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

方法2:配置pip永久信任主机

在用户目录下创建pip文件夹,新建pip.ini文件(路径:C:\Users\你的用户名\pip\pip.ini),写入以下内容:

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

保存后直接执行pip install mkdocs即可,无需每次添加参数。

方法3:导入企业代理证书(企业网络场景)

若为公司自签名代理证书导致问题,将证书导入系统证书库:

  • 导出代理的自签名证书(格式为.crt或.pem)
  • 右键证书文件,选择「安装证书」
  • 选择「本地计算机」,点击「下一步」
  • 选择「将所有证书放入下列存储」,点击「浏览」,选择「受信任的根证书颁发机构」
  • 完成导入后重启命令行,再执行安装命令。

方法4:使用国内PyPI镜像源

切换至国内镜像源规避SSL问题,例如清华镜像:

pip install mkdocs -i https://pypi.tuna.tsinghua.edu.cn/simple

也可配置永久使用国内源,修改pip.ini为:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

内容的提问来源于stack exchange,提问作者Chennakesh Babu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 13:08:24