pip 默认情况下使用的是国外的镜像,在下载的时候速度非常慢,可以用国内清华大学的源,地址为:
https://pypi.tuna.tsinghua.edu.cn/simple
我们可以直接在 pip 命令中使用 -i 参数来指定镜像地址,例如:
pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
以上命令使用清华镜像源安装 numpy 包。
这种只对当前安装对命令有用,如果需要全局修改,则需要修改配置文件。
Linux/Mac os 环境中,配置文件位置在 ~/.pip/pip.conf(如果不存在创建该目录和文件):
mkdir ~/.pip
打开配置文件 ~/.pip/pip.conf,修改如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn