pip国内镜像源配置

以清华大学镜像源为例:https://pypi.tuna.tsinghua.edu.cn/simple

单次使用镜像源

在pip安装命令后添加-i参数指定镜像源:

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

永久配置镜像源

使用命令配置

简单的方式是使用命令配置。

1
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

修改pip配置文件

创建或修改pip配置文件:

  • Linux/MacOS: ~/.pip/pip.conf
  • Windows: %APPDATA%\pip\pip.ini 或 %USERPROFILE%\pip\pip.ini

添加以下内容:

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

常用国内镜像源

恢复默认源

删除配置文件或运行:

1
pip config unset global.index-url