Teach you a trick to easily change the pip source and achieve high-speed downloads
In recent years, Python has become one of the most popular programming languages. Many excellent libraries and frameworks can greatly improve our development efficiency. As a package management tool for Python, pip provides us with a large number of third-party libraries to facilitate our development.
However, due to limitations of the network environment and geographical location, sometimes we may encounter slow download speeds when using pip to download third-party libraries. At this time, we can achieve high-speed downloading by changing the pip source. This article will teach you a way to easily change the pip source.
First, we need to use the pip command to install the third-party library, but before changing the pip source, we can use the following command to view the current pip source:
pip config get global.index-url
After executing the above command, Will return the address of the currently used pip source, such as https://pypi.org/simple/. Next, we can use the following command to list the available pip sources:
pip config list
After executing the above command, all available pip sources and the corresponding addresses and priorities will be returned.
The next step is to teach you how to change the pip source. First, we need to open the pip configuration file, usually in the .pip folder in the user directory. Taking the Windows system as an example, you can use the following command to open the configuration file:
notepad %userprofile%.pippip.ini
If you do not have this file on your computer, you can use the following command to create it:
notepad %userprofile%.pippip.ini
After opening the configuration file, We can see something similar to the following:
[global] index-url=https://pypi.org/simple/
The index-url here is the address of the pip source currently used. Next, we can add other pip source addresses to the configuration file. The following are some commonly used pip source addresses:
# 清华大学 index-url=https://pypi.tuna.tsinghua.edu.cn/simple/ # 阿里云 index-url=http://mirrors.aliyun.com/pypi/simple/ # 豆瓣 index-url=http://pypi.douban.com/simple/
After adding the above pip source address to the configuration file, save and close the configuration file. In this way, we successfully changed the pip source.
Next, we can use the following command to verify whether the pip source has been successfully changed:
pip config get global.index-url
After executing the above command, the changed pip source address will be returned, such as https://pypi .tuna.tsinghua.edu.cn/simple/. At this point, we have easily changed the pip source and achieved high-speed downloading.
When downloading using the changed pip source, we will obviously feel the increase in download speed. At the same time, by choosing the domestic pip source, we can also better avoid the situation where some foreign pip sources are unstable or unreachable.
To summarize, by changing the pip source, we can easily achieve high-speed downloading. Simply modifying the configuration file and selecting a stable and high-speed pip source can improve our development efficiency. Hope this article helps you!
The above is the detailed content of Quickly change pip source and easily achieve high-speed downloading. For more information, please follow other related articles on the PHP Chinese website!