pip安装报错问题处理教程

一、pip安装出错类型

1.1 pip版本过旧导致不能安装

可通过以下命令升级pip

python -m pip install --upgrade pip

1.2 官方的PyPi连接超时

如果是timeout类形错误,那重点怀疑网络问题,可能是官方的PyPi太慢导致。

这类错误可通过在pip.ini中index-url指定为使用本地源进行处理。我这里以清华源为例,具体操作步骤看下边第二大点。

1.3 HTTPS证书问题

现在很多网站都换成了HTTPS,python验证证书没通过时就会拒绝使用PyPi源,通常报错如下:

Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/gg/: There was a
problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsin
ghua.edu.cn', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by S
SLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
 (_ssl.c:726)'),)) - skipping

这类错误可通过在pip.ini中添加trusted-host进行处理。我这里以信任清华源为例,具体操作步骤看下边第二大点。

二、将PyPi切换为本地源并处理证书错误

2.1 查看%APPDATA%路径【可选】

echo %APPDATA%

2.2 创建 %APPDATA%\pip\目录

我这里直接在cmd使用命令创建。图形界面创的话,上一步我们已查到%APPDATA%的指向了一层层根着创即可

mkdir %APPDATA%\pip

2.3 创建pip.ini文件

使用文件编辑器创建一个文本,然后输入以下内容,并将其保存到上边的%APPDATA%\pip\目录下,命名为pip.ini即可(注意不要保存成pip,ini.txt)

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

2.4 验证源成功切换且无报错

我这里以pip安装faker库进行验证,自己随便装什么都行

pip install faker

参考:

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

http://mirrors.ustc.edu.cn/help/pypi.html

https://superuser.com/questions/727924/pip-and-ssl-certificate-errors

猜你喜欢

转载自www.cnblogs.com/lsdb/p/9188204.html