设置pip源国内源

Posted mengyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了设置pip源国内源相关的知识,希望对你有一定的参考价值。

一、为什么要切换本地源 

  目前本地通过pip安装一些python 包的时候经常会遇见一系列的网络连接错误如下所示,其实问题原因很简单本地连接files.pythonhosted.org,导致没有办法安装成功

(venv) D:workspaceflask_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/

  配置完成以后默认会直接走mirrors.aliyun.com来下载

技术图片

 

 

西虹市首富给冰山提提速,我们给pip提提速。

 

以上是关于设置pip源国内源的主要内容,如果未能解决你的问题,请参考以下文章

pip 设置国内源

如何将python中pip源设置为国内源

Linux设置pip国内源

Linux设置pip国内源

pip国内源设置方法

Python设置pip源为国内源及简单操作