SoFunction
Updated on 2025-05-16

Detailed tutorial on installing Python library using Tsinghua University mirror source

Preface

In Python development, installing third-party libraries is an essential step. However, installing the library directly from the official PyPI source can be very slow or even fail due to network reasons. To solve this problem, many domestic mirror sources provide faster download speeds, among which Tsinghua University's mirror sources are one of the most widely used. This article will explain in detail how to use Tsinghua University mirror sources to install Python libraries, including temporary use and permanent configuration methods.

1. Temporary use of Tsinghua University mirror source (recommended)

When installing the library, you can specify the Tsinghua University image source through the --index-url parameter of pip. For example (install the Crypto library):

pip install pycryptodome -i /simple

This method will use Tsinghua University mirror source during this installation without affecting subsequentpipoperate.

2. Permanently configure Tsinghua University mirror source

If you want to use it every timepipAll use Tsinghua University mirror source by default, and can be modifiedpipconfiguration file.

Configuration file path

  • Windows
    • User level:%APPDATA%\pip\
    • System level:C:\Program Files\Python\PythonXX\Lib\site-packages\
  • Linux/macOS
    • User level:~/.pip/
    • System level:/etc/

Configuration steps

  1. Open or create a configuration file

    • Windows users canC:\Users\<your username>\AppData\Roaming\pip\Found or Created indocument.
    • Linux/macOS users can~/.pip/Found or Created indocument.
  2. Add the following

[global]
index-url = /simple
  • Save the file: After saving the file,pipThe Tsinghua University mirror source will be used by default.

3. Verify the configuration

Run the following command to check whether you successfully switch to Tsinghua University image source:

pip config list

If the configuration is successful, you will see an output similar to the following:

-url = /simple

4. Other commonly used mirroring sources

If the Tsinghua University mirror source is not available, you can also choose another mirror source, such as:

  • Alibaba Cloud/pypi/simple/
  • University of Science and Technology of China/simple/
  • Douban/simple/

The configuration method is the same as the Tsinghua University mirror source, just putindex-urlSuper it with the corresponding mirror address.

5. Restore the default source

If you need to restore to the default PyPI source, you can use theindex-urlDelete, or modify it to:

index-url = /simple

6. Things to note

  1. Network issues: If you encounter problems using the mirror source, it may be due to network reasons. You can try switching to another mirror source, or checking the network connection.
  2. Availability of mirror sources: The mirror source may be temporarily unavailable for maintenance or other reasons. If you encounter problems, you can try another mirror source.
  3. Permissions to configuration files: Make sure you have sufficient permissions when modifying the configuration file. If you encounter permission problems, you can use administrator privileges to run the terminal.

7. Summary

Using Tsinghua University mirror source can significantly improve the installation speed of Python libraries, especially in domestic network environments. Through the temporary use and permanent configuration methods described in this article, you can easily switch to Tsinghua University mirroring sources, thereby improving development efficiency. If you encounter problems, you can refer to the precautions in this article, or try other mirroring sources.

The above is the detailed tutorial on using Tsinghua University mirror source to install Python library. For more information about Tsinghua University mirror source to install Python library, please pay attention to my other related articles!