众所周知,pip默认的镜像源在国内访问非常慢,遇到大一些的依赖(如pytorch)会非常容易下载失败,使用国内镜像源即可有效解决该问题,简称pip 换源
。
临时换源
以 pytorch 为例:
清华源:pip install pytorch -i https://pypi.tuna.tsinghua.edu.cn/simple
阿里源:pip install pytorch -i https://mirrors.aliyun.com/pypi/simple/
腾讯源:pip install pytorch -i http://mirrors.cloud.tencent.com/pypi/simple
豆瓣源:pip install pytorch -i http://pypi.douban.com/simple/
永久换源
官方源:pip config unset global.index-url
即 https://pypi.org/simple
清华源: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 http://pypi.douban.com/simple/
常见问题
源不受信任
The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with –trusted-host mirrors.aliyun.com
.
在临时换源中添加参数:--trusted-host {源的URL}
即可,如阿里镜像源 --trusted-host mirrors.aliyun.com
永久换源:pip config set install.trusted-host {源的URL}
,也可在pip配置文件中修改
Windows:%HOMEPATH%\pip\pip.ini
Linux:~/.pip/pip.conf