背景:
当使用pip安装第三方包时,经常会遇到类似以下ssl错误,如安装pytest包,使用命令:
pip install pytest
Collecting pytest
Could not fetch URL https://pypi.python.org/simple/pytest/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) - skipping
Could not find a version that satisfies the requirement pytest (from versions: )
No matching distribution found for pytest
临时解决办法:
使用如下命令:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pytest
永久解决办法:(更改pip安装源为国内镜像)
1.在如下目录创建pip文件夹: C:\Users\XXX\AppData\Roaming;
2.在pip文件夹内创建一个文件:pip.ini;
3.在pip.ini文件内写入如:(本例为阿里镜像);
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
4.保存后,用pip安装时就不会再报SSL证书错误;