Home  >  Article  >  Backend Development  >  Quick settings, one-click configuration of pip mirror sources!

Quick settings, one-click configuration of pip mirror sources!

WBOY
WBOYOriginal
2024-01-16 10:49:061181browse

Quick settings, one-click configuration of pip mirror sources!

Simple operation, easily configure pip mirror source directory!

Introduction:
In the process of using Python to develop, we often need to use pip to install and manage third-party libraries. However, due to network reasons, downloading using the default official mirror source may be slow or even fail. Therefore, many developers will choose to use domestic mirror sources to speed up downloads. This article will introduce how to configure the pip mirror source and provide some commonly used domestic mirror sources for everyone to choose from.

1. How to configure the pip mirror source:

  1. Temporary use:
    When using the pip command, you can specify the mirror source to be used by adding the -m parameter. For example, to use Alibaba Cloud's mirror source:
pip install -m https://mirrors.aliyun.com/pypi/simple 包名
  1. Permanent use:
    If you want to use a mirror source permanently, you can do so by modifying the pip configuration file. Find the folder named pip in the user directory (if there is no such folder, you need to create it manually), create a file named pip.ini under the folder, and then Add the following content to the file:
[global]
index-url = 镜像源地址

Taking the mirror source of Tsinghua University as an example, the configuration file content is as follows:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

2. Commonly used domestic mirror sources:

  1. Alibaba Cloud mirror source: https://mirrors.aliyun.com/pypi/simple

Alibaba Cloud provides a stable and reliable mirror source with fast download speed and is recommended.

  1. Tencent Cloud mirror source: https://mirrors.cloud.tencent.com/pypi/simple

Tencent Cloud mirror source is also a good choice, download It's also very fast.

  1. Tsinghua University mirror source: https://pypi.tuna.tsinghua.edu.cn/simple

The mirror source of Tsinghua University is a well-known open source mirror site in China , the download speed is also very fast.

  1. Huawei Cloud mirror source: https://mirrors.huaweicloud.com/repository/pypi/simple

The mirror source provided by Huawei Cloud is also an optional mirror. source, the download speed is faster.

3. Sample code:
The following is a sample code for pip installation using Alibaba Cloud mirror source:

pip install -m https://mirrors.aliyun.com/pypi/simple requests

After configuring the mirror source, when using pip to install a third-party library, You can use the pip command directly without adding the -m parameter:

pip install requests

4. Summary:
Configuring the pip mirror source can improve the installation speed of third-party libraries and make the development process more efficient. This article introduces how to configure pip image sources, and provides some commonly used domestic image sources for everyone to choose from. Hope this article is helpful to everyone!

The above is the detailed content of Quick settings, one-click configuration of pip mirror sources!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn