一、為什么要切換本地源
目前本地通過pip安裝一些python 包的時候經常會遇見一系列的網絡連接錯誤如下所示,其實問題原因很簡單本地連接files.pythonhosted.org,導致沒有辦法安裝成功
(venv) D:\workspace\flask_parent>pip install flask Collecting flask Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:719)'),)': /packages/9b/93/628509b8d5dc749656a9641f4 caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:719)'),)': /packages/9b/93/628509b8d5dc749656a9641f4 caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:719)'),)': /packages/9b/93/628509b8d5dc749656a9641f4 caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:719)'),)': /packages/9b/93/628509b8d5dc749656a9641f4 caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:719)'),)': /packages/9b/93/628509b8d5dc749656a9641f4 caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1 .1.1-py2.py3-none-any.whl (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:719)'),))
二、目前國內本地源
目前國內比較經常使用的幾個源地址,比較好用的是阿里雲和豆瓣的源,也可以自己來搭建pip源
阿里雲 https://mirrors.aliyun.com/pypi/simple/ 中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣(douban) https://pypi.douban.com/simple/ 清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/ 中國科學技術大學 https://pypi.mirrors.ustc.edu.cn/simple/
三、臨時修改本地源
1、安裝包時直接指定源地址
- 指定的源地址是http協議,需要添加 --trusted-host 添加信任選項
pip install flask -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
- 指定的源地址是https協議
pip install flask -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
四、一勞永逸解決
在windows的用戶主目錄加上一個 pip 文件夾里面添加 pip.ini 文件
[global] index-url = https://mirrors.aliyun.com/pypi/simple/
或者通過命令的方式設置
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
配置完成以后默認會直接走mirrors.aliyun.com來下載
西虹市首富給冰山提提速,我們給pip提提速。