Windows anaconda python3 import ssl报错的解决方案

Windows anaconda python3 import ssl报错的解决方案

问题重现

引用ssl报错ModuleNotFoundError: No module named ‘_ssl’

>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Anaconda\lib\ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
>>>

同时对pip安装东西也造成了影响

C:\Users\YUZI>pip install jieba
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting jieba
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/jieba/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/jieba/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/jieba/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/jieba/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/jieba/
  Could not fetch URL https://pypi.org/simple/jieba/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/jieba/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  Could not find a version that satisfies the requirement jieba (from versions: )
No matching distribution found for jieba

解决方案

我也搜了不少东西,但大多数都是在Linux上的解决办法。
在Windows上其实更简单。只要替换 _ssl.pyd 这个文件就行
anaconda的目录为 D:\Anaconda\DLLs\_ssl.pyd
Python的官网中下载相对应的版本的Python ZIP文件。
例如:
查询本机使用的Python版本
在这里插入图片描述去官网找到相对应的下载页面,这里使用的是Python3.7.2并下载ZIP包
在这里插入图片描述下载完成后解压,并找到我们需要的文件
在这里插入图片描述
复制并替换到Anaconda中,我的目录为 D:\Anaconda\DLLs\_ssl.pyd并测试import与pip

在这里插入图片描述

成功!!

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值