pip is configured with locations that require TLS/SSL, however the ssl module in Python is notable

_Johnny_ 2024-08-15 13:05:02 阅读 76

现象

执行<code>pip install时报错:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Hint: It looks like a path. The path does exist.

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.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', 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.")) - skippingcode>

原因

没有通过该SSL安全协议的认证,通常是由于开启了网络代理、VPN 或者网络抓包等软件的导致的

解决办法

临时关闭代理、VPN 或者网络抓包等软件

最推荐的办法是临时关闭代理、VPN 或者网络抓包等软件,但是如果关闭后下载速度过慢可以尝试后面两种解决办法

通过镜像的 HTTP 源来避免 SSL 认证问题【推荐】

由于是 SSL 是 HTTPS 协议需要的,因此我们可以切换至 HTTP 的镜像站来进行安装下载

HTTPS 现在已经比较普及,有不少镜像源也早已经切换至 HTTPS 协议,但部分镜像源在支持 HTTPS 协议的而同时也还支持 HTTP 协议,下面简单罗列几个 pip 镜像源

# 清华,仅支持 HTTPS

https://pypi.tuna.tsinghua.edu.cn/simple/

# 阿里,HTTP 和 HTTPS 均支持

http://mirrors.aliyun.com/pypi/simple/

https://mirrors.aliyun.com/pypi/simple/

# 豆瓣,HTTP 和 HTTPS 均支持

http://pypi.doubanio.com/simple/

https://pypi.doubanio.com/simple/

安装时第三方包时可以参考如下命令:

pip install xxx-package -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

pip install -r requirements.txt -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

如果想永久使用镜像站,则需要修改配置文件,以 Linux 为例:

vim ~/.pip/pip.conf

修改文件内容如下

[global]

index-url = http://mirrors.aliyun.com/pypi/simple/

[install]

trusted-host = mirrors.aliyun.com

切换至低版本 pip

据说 pip 版本高于 20.3 后才会出现此错误,因此我们可以手动将 pip 版本降级至 20.2.4 或者 20.3b1 等较低版本即可

python -m pip install pip==20.2.4 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

python -m pip install pip==20.2.4 -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

检查环境,如windows配置环境变量

D:\Anaconda3

D:\Anaconda3\Scripts

D:\Anaconda3\Library\bin

【阿里云】PyPI 镜像



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。