Python pip默认使用国外的镜像,在下载安装软件包时速度比较非常慢,要配置成国内镜像源。本文主要介绍Python pip 配置使用国内镜像源的方法。

1、国内镜像源地址

1)国内清华大学的源

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

2)国内中国科学技术大学源

https://pypi.mirrors.ustc.edu.cn/simple

3)国内豆瓣源

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

2、配置使用国内镜像源方法

1)通过命令来临时指定

可以直接在 pip 命令中使用 -i参数来指定镜像地址,例如:

pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

2)Linux上通过修改~/.pip/pip.conf配置文件

打开编辑配置文件 ~/.pip/pip.conf,内容修改成如下:

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

查看配置:

pip config list   

输出:

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

通过上面命令来验证是否修改成功。

3)Windows上通配置文件修改方法

需要在当前对用户目录下(C:\Users\xx\pip,xx 表示当前使用的系统用户)创建一个 pip.inipip.ini文件中输入以下内容:

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

通过pip config list命令查看配置是否修改成功。

推荐文档

相关文档

大家感兴趣的内容

随机列表