Skip to content

Optimizing pip for Faster Package Installation

Domestic Sources

To speed up package installation, you can use domestic sources that are closer to your location. Here are some domestic sources you can use:

shell
https://mirrors.aliyun.com/pypi/simple/
https://pypi.mirrors.ustc.edu.cn/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
https://mirrors.sustech.edu.cn/pypi/simple

Configuring pip

To configure pip to use a domestic source, you can use the following command:

shell
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com

Downloading Packages with pip

You can use the following commands to download packages with pip:

shell
# Download a package and save it to the "dest" directory
pip download openpyxl --dest dest

# Download all dependencies of a package
pip download --only-binary :all openpyxl

# Download a package using a proxy
pip download --only-binary :all --proxy=socks5://127.0.0.1:10808 openpyxl

# Download a package using a specific index-url
pip download --only-binary :all --index-url=https://mirrors.aliyun.com/pypi/simple/ openpyxl

# Download source
pip download --no-binary=:all: openpyxl

Download whl as zip

shell
set pname=poetry
pip download --only-binary :all %pname% --dest %pname%
7z.exe a -r %pname%.zip %pname%
rd /s /q %pname%

Installing Packages with pip

You can use the following commands to install packages with pip:

shell
# Upgrade pip and set the index-url to a domestic source
pip install --upgrade pip --index-url https://mirrors.sustech.edu.cn/pypi/simple

# Download and install a package from a git repository
pip install git+https://github.com/*.git

# Install packages from a specific directory (e.g., "dest")
for %x in (dest\*.whl) do (python -m pip install --no-index --no-deps %x)