将pip源更换到国内镜像

用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。

其中,比较常用的国内镜像包括:

(1)阿里云http://mirrors.aliyun.com/pypi/simple/

(2)豆瓣http://pypi.douban.com/simple/

(3)清华大学https://pypi.tuna.tsinghua.edu.cn/simple/

(4)中国科学技术大学http://pypi.mirrors.ustc.edu.cn/simple/

设置方法:(以清华镜像为例,其它镜像同理)

(1)临时使用:

可以在使用pip的时候,加上参数-i和镜像地址(如

https://pypi.tuna.tsinghua.edu.cn/simple/

例如:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simpleopencv-contrib-python

这样就会从清华镜像安装opencv-contrib-python库。

(2)永久修改,一劳永逸:

windows下,直接在user\xxx目录中创建一个pip目录,如:C:\Users\xx\pip,然后新建文件pip.in

在pip.ini文件中输入以下内容

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple/

[index]

在linux下,

一般要修改配置文件:~/.config/pip/pip.conf (Linux), (没有就创建一个), 将 index-url改成至tuna,例如
在.config文件夹中创建pip/pip.conf

在pip.conf文件中添加清华大学的pypi镜像,要是想用其他的镜像,替换成相应的地址即可。

[global]


index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Leave a Reply

Your email address will not be published. Required fields are marked *