通常我們要使用nltk來下載一些數據集,例如stopwords,我們會這樣做
import nltk
nltk.download('stopwords')
但是有可能會報這樣的錯
nltk.download('stopwords')
[nltk_data] Error loading Punkt: <urlopen error [SSL:
[nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed
[nltk_data] (_ssl.c:590)>
False
我在網上查了很久,很多方法可能無法解決(不知道是不是環境的問題),包括手動下載添加也很麻煩(不知道放在哪),下面這個方法是最方便的
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download('stopwords')
原地址:https://stackoverflow.com/questions/38916452/nltk-download-ssl-certificate-verify-failed