Create a new pip.ini to solve the problem of slow pip download package: the test was successful in pycharm
foreword
When we use pycharm, due to network problems, it is often very slow to download related packages, or even directly overtime and fail to download, wasting life and affecting mood.
Cherish life, start from me!
Method 1. Use a proxy
There are many related tutorials on the Internet.
Method 2. Use pip.ini
The code is as follows (example):
import os
ini = "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple/\n[install]\ntrusted-host=pypi.tuna.tsinghua.edu.cn\n" ; pippath=os.environ["USERPROFILE"]+"\\pip\\" ; exec("if not os.path.exists(pippath):\n\tos.mkdir(pippath)"); open(pippath+"/pip.ini","w+").write(ini)
Running the above code will generate the pip.ini file. Future pip downloads will download the corresponding packages from Tsinghua source.
If you are dissatisfied with Tsinghua, you only need to replace the corresponding source information in the code.
The content of the pip.ini file is as follows:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
Summarize
Get ready to enjoy the speed of light~