This is my eighth day of the August Genwen Challenge

Today I’m going to share with you how to make PIP download speed fly.

Domestic mirror sources are as follows:

Ali cloud: mirrors.aliyun.com/pypi/simple: China university of science and technology pypi.mirrors.ustc.edu.cn/simple douban: pypi.douban.com/simple tsinghua university: pypi.tuna.tsinghua.edu.cn/simple

Tsinghua University download source is recommended here, download speed is fast, and stable.

1. I used Progressbar to test, but the image source of “Ali Cloud” could not be downloaded; Use “Tsinghua” mirror source for perfect download.

< not found >

< Successful installation >

2. On jieba test, the download speed of mirroring really feels “taking off”.

So how do you use it?

All you need to do is add the corresponding image source when PIP is installed.

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jieba
Copy the code

For ease of use, I’ve put together a small script that allows the user to select “image source” and the name of the “extension library” to download.

Run the script to download the extension library.

import os
mirrors = {"Tsinghua university":"https://pypi.tuna.tsinghua.edu.cn/simple "."Ali Cloud":"http://mirrors.aliyun.com/pypi/simple ".University of Science and Technology of China:"https://pypi.mirrors.ustc.edu.cn/simple "."Douban":"http://pypi.douban.com/simple "
           }
print("Tsinghua | | ali cloud USTC | douban")
web = input("Please enter the name of the mirror source you want to select (Tsinghua is recommended) :")
lib = input("Please enter the name of the extension library you want to install:")
Select one of the image sources and download the installation library
os.system("pip3 install -i "+ mirrors[web] + lib)
Copy the code

Operation effect is shown in figure

If you are still bothered, you can configure PIP to install with the configured image source download library by default.

  1. Create a PIP directory directly in the user directory:

C:\Users\ XXX \ PIP (Windows user)

  1. Create a new file “pip.txt”
  2. Enter the following:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy the code

4, rename the text file to “pip.ini”

In this way, future PIP downloads will use the image source by default.

That’s the end of this article. Thank you for watching. Next in this series of Python tips and Tricks, we’ll share information about simplifying Python exceptions

To thank you readers, I’d like to share some of my recent programming favorites to give back to each and every one of you in the hope that they can help you.

Dry goods mainly include:

① Over 2000 Python ebooks (both mainstream and classic books should be available)

②Python Standard Library (Most Complete Chinese version)

③ project source code (forty or fifty interesting and classic practice projects and source code)

④Python basic introduction, crawler, Web development, big data analysis video (suitable for small white learning)

⑤ A Roadmap for Learning Python

All done ~ see personal profile or private letter for complete source code.