Python将pip源更换到国内镜像

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

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

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

LINUX永久修改

(2)LINUX永久修改,一劳永逸:
(a)Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:

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

 Windows 更换PIP国内源如下

永久修改pip源:

1.使用win+R调出运行,输入”%appdata”,回车

 


2.在此文件夹中创建pip文件夹,进入pip文件夹并创建pip.ini文件


3.粘贴如下文件内容即可:

[global]

timeout = 6000

index-url = http://pypi.douban.com/simple/

trusted-host = pypi.douban.com

(如果想修改镜像,修改地址即可)

pip国内的一些镜像:

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

    中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 

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

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

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

posted @ 2020-03-05 21:56  vilenx  阅读(1059)  评论(0编辑  收藏  举报