Since the default addresses for pip and anaconda are very slow to access in China, adding domestic mirrors for acceleration is necessary.

Main Domestic Open Source Mirrors

Tsinghua University https://tuna.tsinghua.edu.cn

Alibaba Cloud http://mirrors.aliyun.com

Tencent Cloud https://mirrors.tencent.com

University of Science and Technology of China https://mirrors.ustc.edu.cn

University of Science and Technology of China http://mirrors.ustc.edu.cn

Tongji University http://mirrors.tongji.edu.cn

Adding and Modifying Conda Sources

According to actual speed tests in Shanghai, Tsinghua University’s mirror is the fastest (Tongji University should be faster in theory, but the actual speed is disappointing, 0-0), so we’ll use it as the default source.

Method 1: Add via command line

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --set channel_priority strict
conda config --set show_channel_urls yes

Method 2: Modify configuration file

echo 'channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
channel_priority: strict
show_channel_urls: true
' > ~/.condarc

Adding and Modifying pip Sources

Like conda, directly use Tsinghua University’s mirror.

# Method 1: Use -i to specify address during installation, e.g. installing sklearn
## Temporary
pip install scikit-learn -i "https://pypi.tuna.tsinghua.edu.cn/simple"
## Permanent
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# Method 2: Modify configuration file
mkdir -p ~/.config/pip
echo '[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
' > ~/.config/pip/pip.conf

Summary

Accelerate installation of Python and R packages in China by modifying pip and conda sources.