Solve the problem of slow installation of third-party libraries in Python

As the world's number one language, Python has many excellent third-party libraries, such as the requests library for reptiles, the openpyxl library for office use, the pygame library for game development, etc. There are thousands of third-party libraries, and they are very It is easy to use, but it is often inconvenient to download and install, such as the following picture:

insert image description here

Obviously, the local network speed is fast, but it becomes a snail when I get here. It takes more than half an hour to download a library with a size of several M, and a slightly larger third-party library can’t be downloaded in an hour or two. It takes a little longer to download and it’s easier Interrupt error

insert image description here

Why is this? It is because the third-party library contributors of Python are basically (please note, it is basic, not all, the pyspider known to bloggers is developed by our Chinese, if you still know which libraries are developed by Chinese, welcome to leave a message in the comment area Oh) are all foreign developers, and the source of the library is also abroad, so our access in China is very slow, which has nothing to do with the local network speed, so what should we do? Of course, this is not a problem for our excellent senior programmers. They have come up with a good solution. Since it is impossible for each of us to move our computers abroad to download, we should simply make a copy of the source website and put it in the country. There is no problem for us to access, and the professional name is the mirror source.

insert image description here

Next, I will introduce several commonly used mirror source websites in China:

1. Aliyuan: https://mirrors.aliyun.com/pypi/simple/

2. Tsinghuayuan: https://pypi.tuna.tsinghua.edu.cn/simple/

3. Douban source: http://pypi.douban.com/simple/

4. University of Science and Technology of China: https://pypi.mirrors.ustc.edu.cn/simple/

How to use the magic weapon in hand? It's very simple. Let's take a look at how to use the mirror source. The usage is as follows:

pip install 库名 -i https://mirrors.aliyun.com/pypi/simple/

The 'library name' here refers to the name of the third-party library we want to install. There must be a space between the '-i' in the middle and the previous library name and the following URL. The latter URL is the domestic mirror source URL. To use Which mirror source is replaced with the corresponding mirror source URL, for example, if we want to install the game library pygame:

pip install pygame -i https://mirrors.aliyun.com/pypi/simple/

Look at the installation speed, it takes off instantly:

insert image description here

Hurry up and try it! ! !

insert image description here

Guess you like

Origin blog.csdn.net/2201_75641637/article/details/128208555