Home  >  Article  >  Backend Development  >  How to adjust pip source to improve download speed

How to adjust pip source to improve download speed

WBOY
WBOYOriginal
2024-01-17 10:40:061293browse

How to adjust pip source to improve download speed

How to modify the pip source to speed up downloading

When using Python for development, we often use pip to install, upgrade, and uninstall Python packages. However, due to the limitations of the domestic network environment, the download speed using the default pip source is slow and may even cause the download to fail. To solve this problem, we can modify the pip source to speed up the download.

1. View the current pip source

Enter the following command in the command line window to view the current pip source:

pip config get global.index-url

The output result is similar to: https://pypi .org/simple/

2. Back up the pip configuration file

In order to avoid misoperation, we need to back up the pip configuration file. Enter the following command in the command line window to copy the pip configuration file to the .pip folder in the current user directory:

cp ~/.pip/pip.conf ~/.pip/pip.conf.bak

3. Modify the pip source to the domestic mirror source

Commonly used domestic pip sources include Alibaba Cloud, Douban, Tsinghua University, etc. Let's take changing to Alibaba Cloud Source as an example. We first need to edit the pip configuration file. Enter the following command in the command line window to open the pip configuration file:

vim ~/.pip/pip.conf

If the file does not exist, create one. Copy the following content into the file:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

Then save and exit.

4. Verify whether the modification is successful

In order to verify whether the modification is successful, we re-execute the command to view the current pip source:

pip config get global.index-url

The output result should be what we just set Alibaba Cloud Source: https://mirrors.aliyun.com/pypi/simple/

5. Install/upgrade the Python package

Now we can install and upgrade the Python package through pip, download The speed will be much faster than before. For example, we can use the following command to install the Flask package:

pip install flask

6. Optional step: Use a proxy

If you still feel that the download speed is not fast enough when using pip, you can try to use a proxy . We can add the following content to the pip configuration file to configure the proxy:

[global]
proxy = http://username:password@proxyserver:port

where username is your proxy username, password is your proxy password, proxyserver is your proxy server address, port is the port number of the proxy server.

Now, you already know how to modify the pip source to speed up downloading and enjoy a faster and more stable Python package downloading experience! Go and try it!

Note: In order to avoid being blocked, we can also switch to different domestic mirror sources regularly. Of course, we can also restore the pip source to the default source by using the following command:

pip config unset global.index-url

The above is the detailed content of How to adjust pip source to improve download speed. 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