直接保存為xxx.py運行即可
自動在用戶文件夾創建pip文件夾,並創建配置文件:pip.ini
從此告別pip install XXXX 下載模塊速度超級慢的問題!
# -*- coding: utf-8 -*-
"""
Python3 --> 解決PIP下載安裝速度慢
"""
import os
PATH = f"C:{os.environ['HOMEPATH']}\\pip"
FILE = 'pip.ini'
# 國內源:鄭州婦科醫院哪家好 http://www.kd0371.com/
# 新版ubuntu要求使用https源,要注意。
DICTURL = {
'清華': 'https://pypi.tuna.tsinghua.edu.cn/simple/',
'阿里雲': 'http://mirrors.aliyun.com/pypi/simple/',
'中國科技大學': 'https://pypi.mirrors.ustc.edu.cn/simple/',
'華中理工大學': 'http://pypi.hustunique.com/',
'山東理工大學': 'http://pypi.sdutlinux.org/',
'豆瓣': 'http://pypi.douban.com/simple/'
}
# pip.ini 配置文件內容
INFO = f"""[global]
index-url = {DICTURL['阿里雲']}
[install]
trusted-host=mirrors.aliyun.com"""
# 判斷pip文件夾是否存在,存在跳過,不存在創建
if not os.path.exists(PATH):
os.mkdir(PATH)
# 創建配置文件,寫入內容
with open(os.path.join(PATH, FILE), 'w', encoding='utf-8') as f:
f.write(INFO)
print(f'用戶路徑:{PATH}\n配置文件:{FILE}\n****創建成功!****')