By default, pip uses foreign mirrors, which makes downloading very slow. In this article, we introduce using Tsinghua University's domestic source, with the address:

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

We can directly use the-iparameter to specify the mirror address, for example:

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

The above command uses the Tsinghua mirror source to install the numpy package.

Set as default

After upgrading pip to the latest version, configure it:

python -m pip install --upgrade pip
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

If your network connection to the default pip source is poor, temporarily use this mirror site to upgrade pip:

python -m pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade pip

Modify configuration

If you need to make global changes, you need to modify the configuration file.

In Linux/Mac OS environments, the configuration file is located at ~/.pip/pip.conf (if it does not exist, create the directory and file):
mkdir ~/.pip

Open the configuration file~/.pip/pip.conf, and modify as follows:

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

Check the mirror address:

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

You can see that the mirror has been successfully modified.

Under Windows, you need to create a pip.ini in the current user directory (C:\Users\xx\pip, xx represents the current user, for example, Zhang San) and enter the following content in the pip.ini file:

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

Other domestic mirror sources

  • Tsinghua University TUNA mirror source: https://pypi.tuna.tsinghua.edu.cn/simple
  • Alibaba Cloud mirror source: http://mirrors.aliyun.com/pypi/simple/
  • University of Science and Technology of China mirror source: https://mirrors.ustc.edu.cn/pypi/simple/
  • Huawei Cloud mirror source: https://repo.huaweicloud.com/repository/pypi/simple/
  • Tencent Cloud mirror source: https://mirrors.cloud.tencent.com/pypi/simple/