pip使用国内镜像源

发布时间 2024-01-04 14:45:34作者: 梁永旺

默认情况下pip使用的是国外的镜像源,在下载的时候速度非常慢。
可以直接在pip命令中使用-i参数来指定镜像地址

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

这种只对当前安装对命令有用,如果需要全局修改,则需要修改配置文件
在Linux环境中,配置文件在 ~/.pip/pip.conf(如果不存在创建该目录和文件)

mkdir ~/.pip
vim ~/.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'

windows下当前对用户目录下(C:\Users\xx\pip,xx 表示当前使用对用户,比如张三)创建一个 pip.ini在pip.ini文件中输入以下内容:

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

其他国内镜像源
● 中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple
● 豆瓣:http://pypi.douban.com/simple/
● 阿里云:http://mirrors.aliyun.com/pypi/simple/