设置pip源国内源

一、为什么要切换本地源 

  目前本地通过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提提速。

 

posted on 2020-03-12 23:55  梦雨情殇  阅读(4363)  评论(0编辑  收藏  举报

导航