引用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

成功!!
Copyright © 2018-2019 - All Rights Reserved - www.pianshen.com
在Windows上,遇到anaconda运行Python时进口ssl模块错误:ModuleNotFoundError: No module named '_ssl',同时也影响了pip的正常使用。解决方法是直接替换Anaconda目录下的_ssl.pyd文件。从Python官网下载对应版本的Python ZIP文件,解压后找到_ssl.pyd文件,将其复制到Anaconda的DLLs目录下,即可解决问题。
2281

被折叠的 条评论
为什么被折叠?



