将PIP更换到国内镜像

2019年9月15日 1208点热度 0人点赞 0条评论

用 pip 安装库文件时,默认使用国外的 Mirrors ,因此在国内的下载速度会比较慢,可能只有 10KB/s 。幸好,国内的一些顶级科研机构已经给我们准备好了各种 Mirrors 。这里推荐清华大学的 Mirrors :

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

设置方法:

(1)临时使用:

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

(2)永久修改:

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

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

保存并退出,再运行 pip 就飞起来了。

方式二:输入pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple回车(适用较新版本的pip)

耗子

练习时长 4 年半的个人程序员 喜欢PHP、Go、Vue 和 Python Music~

文章评论

Loading...