pip 国内源提速

来源:互联网 发布:python 批量打包apk 编辑:程序博客网 时间:2024/05/16 17:22

经常在使用Python的时候需要安装各种模块,而pip是很强大的模块安装工具,但是由于国外官方默认pip访问速度慢,经常被墙,导致无法安装,所以我们最好是将自己使用的pip源更换一下,这样就能解决被墙导致的装不上库的烦恼。
网上有很多可用的国内镜像源,例如

http://pypi.douban.com/  豆瓣http://pypi.hustunique.com/  华中理工大学http://pypi.sdutlinux.org/  山东理工大学http://pypi.mirrors.ustc.edu.cn/  中国科学技术大学https://pypi.tuna.tsinghua.edu.cn/simple 清华http://mirrors.aliyun.com/pypi/simple/ 阿里

国内使用得比较多并且速度比较快的是清华大学和阿里的pip源,清华大学的是官网pypi的镜像,每隔5分钟同步一次,地址为
https://pypi.tuna.tsinghua.edu.cn/simple
临时使用:
可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent,这样就会从清华这边的镜像去安装gevent库。
永久使用:

Linux下,修改 ~/.pip/pip.conf (没有就自己创建), 修改 index-url至清华源,简洁的配置内容如下:

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

windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,配置同上,稍微详细一点的配置内容可以如下

 [global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple #清华源,可以换成其他的源trusted-host = pypi.tuna.tsinghua.edu.cn            #添加清华源为可信主机,要不然可能报错disable-pip-version-check = true          #取消pip版本检查,排除每次都报最新的piptimeout = 120
原创粉丝点击