python安装pip install报错Could not fetch URL https://pypi.org/simple/pip/...更换镜像源

更换镜像源

    • 一. 现象
      • pycharm使用 pip install xxx安装包时,一直报错:
    • 二. 原因:
    • 三. 解决办法:
      • 一. 临时使用
      • 二. 永久更改
      • 三. 永久更改
        • 1. Windows
          • windows环境下
          • Windows(示例win10)
        • 2. Linux or Mac
        • 3. Pycharm中修改库下载源

一. 现象

pycharm使用 pip install xxx安装包时,一直报错:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=No
ne)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation
 of protocol (_ssl.c:1123)'))': /simple/flask/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=No
ne)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation
 of protocol (_ssl.c:1123)'))': /simple/flask/
ERROR: Could not find a version that satisfies the requirement xxx (from versions
: none)
ERROR: No matching distribution found for xxx
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming th
e ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exce
eded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in vio
lation of protocol (_ssl.c:1123)'))) - skipping

二. 原因:

pypi.python.org在国内被墙了,无法从python官网url下载。

三. 解决办法:

一. 临时使用

更改为国内的镜像源:(xxx为安装的包)

pip install xxx -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx
  • 豆瓣(douban) http://pypi.douban.com/simple/

  • 阿里云 http://mirrors.aliyun.com/pypi/simple/

  • 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

  • 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

  • 华为云:https://repo.huaweicloud.com/repository/pypi/simple

注:还尝试了一种方法,是加上–trusted-host

执行 pip install xxx -i https://pypi.org/simple --trusted-host pypi.org 但是仍然报错

这次应该url对了,但是还是一直WARNING

二. 永久更改

在python的命令提示符中运行以下语句,该条语句将pip的下载源永久更改为某个镜像站,这里以清华大学开源镜像站为例:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

三. 永久更改

1. Windows
windows环境下

在用户目录中创建一个文件夹,该文件夹的命名为pip;在该pip文件夹中新建一个文件pip.ini,pip.ini的内容如下:(完整路径:C:\Users\用户名\pip\pip.ini)

[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple 
[install]  
trusted-host=pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true  
timeout = 600
Windows(示例win10)

1、文件管理器文件路径地址栏敲:%APPDATA% 回车,快速进入 C:\Users\电脑用户\AppData\Roaming 文件夹中
2、新建 pip 文件夹并在文件夹中新建 pip.ini 配置文件
3、新增 pip.ini 配置文件内容

[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
2. Linux or Mac

首先在用户目录下新建.pip文件夹

mkdir ~/.pip

在该目录下新建配置文件pip.conf,输入如下内容,保存:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3. Pycharm中修改库下载源

在setting中按如下路径打开包下载
python安装pip install报错Could not fetch URL https://pypi.org/simple/pip/...更换镜像源_第1张图片
点击Manage Respositories,点击+添加国内源路径即可







破壳的小企鹅

python更换国内镜像源三种实用方法

SevenBerry

python安装pip install报错Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirm

牧竹子

Python环境安装并永久配置镜像源

你可能感兴趣的:(#,python,python,pip,开发语言)