在安装好python pip 之后,默认pip 使用的是国外源下载依赖,由于GFW会导致网速很慢,需要配置国内源加快下载速度
临时配置
在安装依赖的时候 通过 -i
参数临时指定要用到的源
pip install bs4 -i https://pypi.tuna.tsinghua.edu.cn/simple
永久配置
将国内源写入到全局配置中,下次安装依赖会自动启用国内源下载
[随便选一个自己喜欢的源就好,就python 来说douban 源使用的比较多的一个,估计是douban 是用python 写的原因吧。]
# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url https://pypi.douban.com/simple/
如果配到目标源使用了http协议,会导致安装的时候报错,如下图
解决方法
直接加上下面一句话就好了
pip config set global.trusted-host mirrors.cloud.tencent.com