Fundamentals 7 min read

Speed Up Python Package Installs: Configure Pip Mirrors in Minutes

This guide explains why the default PyPI source is slow for Chinese users and provides step‑by‑step instructions for temporarily or permanently switching pip to domestic mirror servers, covering command‑line configuration and manual file editing across Windows, macOS, and Linux.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Speed Up Python Package Installs: Configure Pip Mirrors in Minutes

What is pip?

pip is the official Python package manager, similar to an app store, used to install, uninstall, update, and list third‑party libraries. By default it connects to the overseas PyPI server, which can be very slow for users in China.

Mirror sources

A mirror (or replica) server hosts a copy of the entire PyPI repository on domestic servers, providing much faster download speeds. Common Chinese mirrors include Tsinghua University, Alibaba Cloud, and others.

Mirror source list
Mirror source list

Configuring pip mirrors

Temporary configuration

Use the -i option with the desired mirror URL for a single install command, e.g.:

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

Or install a specific version of a package from Alibaba Cloud:

pip install numpy==1.24.3 -i https://mirrors.aliyun.com/pypi/simple/

Permanent configuration – command line

Run the following command to set the global index URL (example uses Tsinghua mirror):

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

If the mirror shows an “untrusted host” warning, add it to the trusted hosts list: pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn Verify the configuration with:

pip config list

Permanent configuration – manual file edit

When command‑line configuration fails or you need multiple mirrors, edit the pip configuration file directly.

Windows

File path: C:\Users\<username>\pip\pip.ini. Create the folder and file if they do not exist, then add:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn
# optional backup source
# extra-index-url = https://mirrors.aliyun.com/pypi/simple/

macOS / Linux

File path: ~/.config/pip/pip.conf. Create the directory if needed, then add:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
# optional timeout in seconds
timeout = 120

Check the settings with pip config list.

Conclusion

Use temporary settings for occasional installs, command‑line permanent settings for quick setup, or manual file edits for advanced customization such as backup mirrors or timeout adjustments. Switch to another mirror if the current one becomes slow or unavailable.

PythonConfigurationpipmirrorspackage-management
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.