【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/

方式一:临时使用国内pypi镜像安装

pip install -i http://pypi.douban.com/simple/ numpy
pip install -i http://pypi.douban.com/simple/--trusted-host pypi.douban.com  #此参数“--trusted-host”表示信任,如果上一个提示不受信任,就使用这个

方式二:永久使用国内pypi镜像安装

有没有什么办法,可以像往常一样,只使用pip install <包名>,但是直接使用指定的镜像源呢?

windows环境:

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

 centOS7环境:

(pd_test) [root@67 ~]# pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /root/.config/pip/pip.conf

效果:

 参考文档:

Python pip配置国内源

 

原文地址:https://www.cnblogs.com/kaerxifa/p/12927994.html