Python更换国内镜像

由于python使用pip安装第三方包的时候下载速度感人,并且有时候回报错,因此换为国内镜像源是个不错的途径;

在网上搜索很久,有的方法不太对,现总结如下:

0、国内镜像源:

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

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

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

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

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

方式1、在命令行模式下使用指令 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 模块名

方式2、修改pip配置文件,可以一劳永逸:

win7以上系统可以使在C:\ProgramData\pip\pip.ini下修改如下:

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

linux系统如下:

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

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

参考资料:pip配置官方指导
Configuration - pip documentation v21.3.1 (pypa.io)

 

posted @ 2021-11-28 16:38  annjk  阅读(879)  评论(0编辑  收藏  举报