windows: pip install 报错SSLError Can‘t connect to HTTPS URL because the SSL module is not available

Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."

  • 系统环境
  • 错误描述
  • 解决方法
    • 临时源测试
    • windows命令行更换源(永久)

系统环境

  • windows
  • anaconda
  • pip清华源

错误描述

通过pip install 安装不成功,会报错(Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

错误详情如下:

ghua.edu.cn', port=443): Max retries exceeded with url: /simple/opencv-python/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")
) - skipping
ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)                                                                     
ERROR: No matching distribution found for opencv-python                                                                                                                
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.                                                     
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.c
.cn', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping    ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)
ERROR: No matching distribution found for opencv-python
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.c
n', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping        
WARNING: There was an error checking the latest version of pip.

具体是什么错误什么原因导致,不去深究了。或许是源本身有问题?下面直接提供解决方法,通过更换源解决了该错误

解决方法

临时源测试

pip install opencv-python -i http://pypi.douban.com/simple
# 依然会报以下错误,提示 is not a trusted
Looking in indexes: http://pypi.douban.com/simple
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use H
TTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)
ERROR: No matching distribution found for opencv-python
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use H
TTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
WARNING: There was an error checking the latest version of pip.

加上--trusted-host,命令如下不会报错了

pip install opencv-python -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

windows命令行更换源(永久)

有很多人是用手动方式,在C:\Users\Administrator\AppData\Roaming下,创建一个pip文件夹,编辑pip.ini文件
这里采用命令操作,win+R然后cmd的命令行换源,输入以下两行指令即可

# 以阿里云为例
pip config set global.index-url http://mirrors.aliyun.com/simple
pip config set global.trusted-host mirrors.aliyun.com

# 还有其他很多源,比如以下:
# http://mirrors.aliyun.com/pypi/simple 阿里云
# http://pypi.douban.com/simple 豆瓣
# https://pypi.tuna.tsinghua.edu.cn/simple 清华大学
# http://pypi.mirrors.ustc.edu.cn/simple 中国科学技术大学

你可能感兴趣的:(windows,pip,https)