Completely solve the problem of slow downloading of Python packages

Because Python uses foreign mirrors by default, sometimes the download is very slow. The fastest way is to add domestic sources in the download command:

pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple

Commonly used domestic sources are as follows:

Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/

Alibaba 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/

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

However, it is particularly inconvenient to enter the URL every time. In fact, we can modify the download source of pip globally, so that there is no need to write the path of the domestic source in the future.

Windows (example win10)

Create a file pip.ini

document content

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

In the user directory, create a new pip folder

Check whether the configuration is successful:

pip config list


See if the download speed has become faster

If it is troublesome, directly execute the following python code to quickly get the configuration.

import os
ini = "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple/\n"
pippath=os.environ["USERPROFILE"]+"\\pip\\"
exec("if not os.path.exists(pippath):\n\tos.mkdir(pippath)")
open(pippath+"/pip.ini","w+").write(ini)

Linux or Mac

First create a new .pip folder in the user directory

mkdir ~/.pip

Create a new configuration file pip.conf in this directory, enter the following content, and save:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Modify library download source in Pycharm

Open the package download according to the following path in the setting


Click Manage Respositories


Click + to add a domestic source path.


Guess you like

Origin blog.csdn.net/XingLongSKY/article/details/109634785