Home  >  Article  >  Backend Development  >  Tips to optimize pip download speed: modify the mirror source

Tips to optimize pip download speed: modify the mirror source

WBOY
WBOYOriginal
2024-01-17 10:47:13518browse

Tips to optimize pip download speed: modify the mirror source

Tips to improve pip download speed: modify the source address, specific code examples are required

With the widespread application of Python language, pip has become the standard for Python package management tool. Many people may encounter slow download speeds when using pip for package installation. Since pip will connect to the official Python Package Index (PyPI for short) by default, access speed in China may be slow.

In order to solve this problem, we can improve the download speed by modifying the pip source address. In China, there are some excellent mirror sources that can replace PyPI, such as:

  1. Tsinghua University Open Source Software Mirror Station (https://mirrors.tuna.tsinghua.edu.cn/)
  2. Alibaba Cloud PyPI Mirror (https://mirrors.aliyun.com/pypi/simple/)
  3. Douban PyPI Mirror (https://pypi.douban.com/simple/)

The following takes the Tsinghua University open source software mirror station as an example to introduce how to modify the pip source address to improve download speed.

First, enter the following command on the command line to open the pip configuration file:

pip config edit

This command will open the pip configuration file in the default text editor. If there is no default text editor in the system, you can use the following command to manually open the configuration file:

pip config --editor <编辑器命令> edit

Then, add the following content to the configuration file:

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

Save the file and exit the editor. In this way, pip will use the Tsinghua University open source software mirror station as the default source address.

If you also want to keep PyPI as an alternative source address, you can add the following to the configuration file:

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

Save the file and exit the editor.

After the configuration is completed, you can use the modified pip source address to install the Python package. For example, execute the following command to install the requests package:

pip install requests

In this way, you can enjoy faster download speeds.

In addition to modifying the pip source address by modifying the configuration file, you can also temporarily switch the source by directly specifying the source address on the command line. For example, execute the following command to install the requests package:

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

This will use the Tsinghua University open source software mirror station as the temporary source address without modifying the configuration file.

To sum up, modifying the pip source address is an effective way to improve download speed. In China, using domestic mirror sources such as Tsinghua University’s open source software mirror station can significantly speed up package downloads. I hope the above tips can be helpful to everyone when using pip.

The above is the detailed content of Tips to optimize pip download speed: modify the mirror source. 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