Python3 解決windows里PIP下載安裝速度慢


  直接保存為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****創建成功!****')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM