SoFunction
Updated on 2025-05-17

A comprehensive tutorial on installing Python packages and configuring mirrors using Tsinghua Source

Preface

Managing dependencies is a very important step in Python projects.pipIt is a package management tool officially recommended by Python, which can help us quickly install the required third-party libraries and tools. However, by default,pipThe PyPI mirror server you use may sometimes encounter slow access speed or connection problems, especially for users in mainland China. Therefore, many developers choose to use domestic mirror sources to speed up the installation process of packages. The PyPI mirror provided by Tsinghua University is a very excellent choice.

This article will install Python packages through Tsinghua Source, and introduce common methods and mirror source configurations to help you manage the dependency environment of Python projects more efficiently.

1. Use Tsinghua Source when installing Python packages

In mainland China, installing Python packages using Tsinghua University mirror sources usually significantly improves download speeds. Tsinghua's PyPI mirror source provides images that are fully synchronized with the official PyPI and provides stability and accuracy consistent with the official source.

1.1 Using Tsinghua Source Installation Package

When installing Python packages, you can specifypipUse Tsinghua Source for installation. Here is an example command:

pip install -r  -i /simple

-r Indicates installationAll dependency packages in the file. pass-iParameters specify the mirror source URL, tellpipUse Tsinghua Source to download and install packages.

1.2 Permanent configuration of Tsinghua Source

If you wishpipTsinghua Source is used by default every time without manually specifying it every time. You can use it inpipModify in the configuration file.

  • For Linux and macOS users, you can create or modify it in the user directory~/.pip/document.
  • For Windows users, the configuration file path is%APPDATA%\pip\

Add the following to the configuration file:

[global]
index-url = /simple

so,pipThe package will be downloaded by default without manually specifying it every time.

2. Common Python package installation methods

Python's package management toolpipSupports multiple installation methods, depending on your needs.

2.1 Installing a single package

To install a single Python package, you can use the following command:

pip install Package name

For example, installnumpy

pip install numpy

2.2 Install from

In Python projects, it is usually usedTo list all dependencies for easy installation in different environments. Use the following command:

pip install -r 

File example:

numpy==1.21.2
pandas==1.3.3
scikit-learn==0.24.2

2.3 Installing a specific version of the package

If you need to install a specific version of a package, you can use the following command:

pip install Package name==Version number

For example, installnumpyVersion 1.21.2:

pip install numpy==1.21.2

2.4 Install using local packages

If you have a local Python package or.Package files can be installed using the following command:

pip install /path/to/

or:

pip install /path/to/

2.5 Install using Git repository

You can also install Python packages directly from your Git repository. Suppose you want to install a package hosted on GitHub:

pip install git+/username/

3. Other advantages of Tsinghua mirror source

In addition to PyPI mirroring, Tsinghua Source also provides many other resources to help developers accelerate download and installation.

3.1 Fast speed and high stability

Tsinghua Source is one of the most popular PyPI images in China, with high stability and download speed. It can significantly improvepipInstallation speed, especially in mainland China, reduces installation failure problems caused by network instability.

3.2 Synchronize with official sources

Tsinghua Source keeps synchronized with the official PyPI server to ensure the latest image content. When the Python package is updated, Tsinghua Source will synchronize in the shortest time to ensure that users can access the latest version.

3.3 Supports HTTP and HTTPS

Tsinghua Source supports HTTP and HTTPS protocols. Developers can choose corresponding protocols according to their needs to ensure the security and stability of the download process.

4. Other commonly used mirror sources

In addition to Tsinghua University mirroring sources, there are some other commonly used mirroring sources in China that can be used:

  • Alibaba Cloud:

    pip install -r  -i /pypi/simple/
    
  • University of Science and Technology of China:

    pip install -r  -i /simple/
    
  • Huawei Cloud:

    pip install -r  -i /repository/pypi/simple/
    

By selecting the right mirror source, you can install and manage Python packages faster and improve development efficiency.

5. Summary

Installing Python packages using Tsinghua Source can significantly improve the download speed of packages, especially suitable for users in mainland China. By configurationpipUsing Tsinghua Source or other domestic mirroring sources, you can easily manage dependencies on Python projects. Common package installation methods includeInstall, install the specified version, install from the Git repository, etc. Mastering these methods will help you manage your Python environment more efficiently.

This is the article about installing Python packages and configuring mirrors using Tsinghua Source. For more related content on installing Python packages and configuring mirrors in Tsinghua Source, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!