During the Python development process, we often encounter a problem, that is, when using pip to install dependent libraries, the download speed is abnormally slow, and the download may even fail. At this time, we need to use the pip source change method to solve this problem by changing the source address and quickly download the required dependent libraries.
So, let’s take a closer look at how to use pip to change the source method.
First, we need to open the pip configuration file pip.ini. This file is generally stored in the user folder. For example, if my user name is "test", the file path is C:Users estpippip.ini.
If there is no pip.ini file in your computer, you can create a new one. If there is no pip folder in your computer, you can create an empty folder named pip under the user folder, and then create it in the Create a new pip.ini file in the folder.
Next, add the following content to the pip.ini file:
[global]
trusted-host=mirrors.aliyun.com
index-url=https:/ /mirrors.aliyun.com/pypi/simple/
The above address is the source address of Alibaba Cloud, and the speed is relatively stable, so it can be used as the preferred source address. Of course, if you have other more stable source addresses, you can also use them.
After completing the above steps, we need to reopen the command line window and enter the following command to test whether the source address has been successfully changed:
pip install pandas -i https://pypi.tuna .tsinghua.edu.cn/simple/
The pandas here is just an example dependent library. You can download other libraries according to your needs. What needs to be noted here is to add the "-i" parameter and use the above Change the source address, so that we can effectively test whether our source address has been changed successfully.
If the dependent library can be downloaded quickly during this process, it means that we have successfully changed the source address and can successfully use pip to install the dependent library.
In addition to the source address of Alibaba Cloud, there are many other source addresses to choose from, such as the source address of the University of Science and Technology of China, the source address of Tsinghua University, etc. The specific address can be searched by yourself.
In short, the pip source changing method is a very effective method to solve the problem of slow pip download speed, which can greatly improve our development efficiency. I hope this article can help everyone and save you from the troubles when using pip.
The above is the detailed content of Simplify downloading dependent libraries: use pip source replacement method to solve troubles. For more information, please follow other related articles on the PHP Chinese website!