因為python默認使用的是國外鏡像,有時候下載非常慢,最快的辦法就是在下載命令中增加國內源:
pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
“常用的國內源如下:
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
”
但是每次都要輸入url特別不方便,其實我們可以全域修改pip的下載源,這樣以后都不需要寫國內源的路徑了,
Windows(示例win10)
創建一個檔案pip.ini
檔案內容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
在用戶目錄下,新建一個pip檔案夾
查看是否配置成功:
pip config list
看一下下載速度是不是變快了
如果嫌麻煩,直接執行如下python代碼,快速搞定配置,
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
首先在用戶目錄下新建.pip檔案夾
mkdir ~/.pip
在該目錄下新建組態檔pip.conf,輸入如下內容,保存:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Pycharm中修改庫下載源
在setting中按如下路徑打開包下載
點擊Manage Respositories
點擊+添加國內源路徑即可,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/220992.html
標籤:其他
上一篇:臥槽!原來爬取B站彈幕這么簡單
下一篇:Python影像讀寫方法對比
