pip 命令修改国内源时,提示有多个位置的配置文件可能产生作用,所以最好的方式是在当前环境下直接用命令修改pip 的config 文件
常用命令
pip config set
// 这个命令允许我们以name=value的形式配置某些项,比如设置镜像源:
pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
pip config get
// 这个命令允许我们查看某个配置项的值,比如查看镜像源配置:
pip config get global.index-url
pip config edit
// 这个命令允许我们用一个编辑器打开配置文件进行编辑,如果我们没有指定--editor选项,就会用VISUAL或者EDITOR环境变量的值作为编辑器,如下命令:
pip config --editor=vi edit
pip config list
// 这个命令以name=value的形式输出当前配置,假如我们已经执行了上面的pip config set命令,这时再执行 pip config list就会输出如下:
global.index-url='https://mirrors.cloud.tencent.com/pypi/simple'
pip config debug
// 这个命令列出各个配置文件位置及其内容,在我系统上执行pip config debug后输出如下:
env_var:
env:
global:
/etc/xdg/pip/pip.conf, exists: False
/etc/pip.conf, exists: False
site:
/usr/pip.conf, exists: False
user:
/home/xxx/.pip/pip.conf, exists: False
/home/xxx/.config/pip/pip.conf, exists: True
global.index-url: https://mirrors.cloud.tencent.com/pypi/simple
global.hello: world
pip config unset
// 这个命令允许我们删除一个配置,比如下面命令删除了镜像的配置:
pip config unset global.index-url
国内源
默认情况下 pip 使用的是国外的镜像,使用国内清华大学的源,地址为:
https://pypi.tuna.tsinghua.edu.cn/simple
我们可以直接在 pip 命令中使用 -i 参数来指定镜像地址,例如:
pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
其他源
中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple
豆瓣:http://pypi.douban.com/simple/
本文介绍了如何使用pipconfig命令修改pip的配置文件,以切换到国内镜像源,如清华大学源。通过设置global.index-url,可以加快Python包的下载速度。此外,还列举了其他可用的国内源,如中国科学技术大学和豆瓣源。

541

被折叠的 条评论
为什么被折叠?



