在安裝第三方庫的時候,Python報錯pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
python開發中,我們經常用到pip工具:
然而,有時候下載速度非常慢………………
下面介紹兩種方式,解決下載問題:
一:每次下載手動更改鏡像
- 我們可以選用國內的鏡像下載:
-
國內源:
清華: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 命令格式:
- pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 工具包
二:更改電腦默認鏡像,之后便可用 pip install 命令快速下載
針對linux系統:
進入家目錄下
ctrl + h 快捷鍵顯示隱藏文件,看是否有無 .pip文件夾,無則創建;文件夾下,創建一個pip.conf 文件,文件內容下
[global]
timeout = 6000
index-url = http://pypi.douban.com/simple/
[install]
use-mirrors = true
mirrors = http://pypi.douban.com/simple/
trusted-host = pypi.douban.com
針對windows系統:
可以在我的電腦,搜索 %APPDATA%(代表系統變量)
回車之后,創建pip文件夾,在文件夾中創建pip.ini文件,文件內容如下
[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
即可成功修改pip鏡像路徑
或者,找到python安裝目錄下的:\Lib\site-packages\pip\models\index.py文件,將PYPI的值改為你所需要的源即可