pip源更换到国内镜像(Linux, Windows)

将pip源更换到国内镜像


用pip管理工具安装库文件时,默认使用国外的源文件,所以在国内的下载速度会比较慢,可能只有50KB/s。幸亏,国内的一些顶级科研机构已经给咱们准备好了各类镜像,下载速度可达2MB/s。
其中,比较经常使用的国内镜像包括:ubuntu

(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/
(5)华中科技大学http://pypi.hustunique.com/windows

注意:新版ubuntu要求使用https源。编辑器

设置方法:(以清华镜像为例,其它镜像同理)
(1)临时使用(推荐在pip源卡顿时,临时换源使用):
能够在使用pip的时候,加上参数-i和镜像地址(如https://pypi.tuna.tsinghua.edu.cn/simple),
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。工具

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

(a) 快速设置(推荐使用):url

若是pip版本>=10.0.0,则可以使用如下pip config set global.index-url命令进行配置,具体示例(以清华大学国内镜像源为例)以下:.net

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

(b)Linux下,修改 ~/.pip/pip.conf (没有就建立一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容以下:code

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

(c) windows下,直接在user目录中建立一个pip目录,如:C:\Users\xx\pip,而后新建文件pip.ini,即 %HOMEPATH%\pip\pip.ini,在pip.ini文件中输入如下内容(以豆瓣镜像为例):ip

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com

建立pip.ini文件能够用文本编辑器,例如 sublime text3。

pip.ini文件中的内容以下:

最后在cmd尝试安装pandas,你会发现已经pip改用清华镜像了。

———————————————— 版权声明:本文为CSDN博主「Chaser_LittleBee」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处连接及本声明。 原文连接:https://blog.csdn.net/sinat_21591675/article/details/82770360