pip安装pyinstaller出现SSL错误无法安装,求可行解决方法
pip安装Python包SSL证书验证失败解决方案
完整报错日志如下:
D:\Work Folder>pip install pyinstaller Requirement already satisfied: pyinstaller in c:\python\python38\lib\site-packages (3.6) Requirement already satisfied: pywin32-ctypes>=0.2.0 in c:\python\python38\lib\site-packages (from pyinstaller) (0.2.0) Requirement already satisfied: setuptools in c:\python\python38\lib\site-packages (from pyinstaller) (41.2.0) Requirement already satisfied: altgraph in c:\python\python38\lib\site-packages (from pyinstaller) (0.17) Requirement already satisfied: pefile>=2017.8.1 in c:\python\python38\lib\site-packages (from pyinstaller) (2019.4.18) Requirement already satisfied: future in c:\python\python38\lib\site-packages (from pefile>=2017.8.1->pyinstaller) (0.18.2) Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)'))) - skipping
方案1:单次安装临时跳过SSL验证
安装命令后追加--trusted-host参数跳过pypi官方源的SSL校验,命令如下:
pip install pyinstaller --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
如果是升级pip本身,命令为:
pip install --upgrade pip --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
注:该方法为单次临时生效,仅建议在可信网络环境下使用
方案2:全局配置跳过SSL验证(永久生效)
配置后所有pip安装操作无需每次追加参数,Windows系统配置步骤:
- 打开当前用户根目录(路径为
C:\Users\你的系统用户名) - 新建名为
pip的文件夹,在文件夹内新建名为pip.ini的配置文件 - 写入以下内容后保存,重启命令行即可生效
[global] trusted-host = pypi.org pypi.python.org files.pythonhosted.org
注:全局跳过SSL验证存在一定安全风险,仅建议个人自用设备在可信网络环境下配置
方案3:替换国内镜像源(同时解决下载慢+SSL问题)
使用国内pypi镜像源可同时解决SSL验证失败和官方源下载速度慢的问题,是最推荐的解决方案,全局配置步骤:
- 同方案2的路径打开/新建
pip/pip.ini文件 - 写入以下内容后保存,重启命令行即可生效
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn
单次安装临时使用国内源的命令:
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
方案4:修复本地根证书
如果上述方案都无效,为本地系统根证书异常导致,修复步骤:
- 先临时跳过SSL升级证书库:
pip install --upgrade certifi --trusted-host pypi.org --trusted-host files.pythonhosted.org
- 确认系统时间、日期、时区配置完全正确,时间误差过大会导致SSL验证失败
- 打开Windows控制面板的
Internet选项-内容-证书,选择受信任的根证书颁发机构标签,点击高级,勾选所有证书用途后确认,重启系统即可
内容的提问来源于stack exchange,提问作者Rahil
相关产品推荐
相关产品推荐

