在使用NLP NLTK时,会出现 nltk.download('stopwords')错误,这个问题目前是找到两个解决办法:
方法一:
直接手动下载 stopwords.zip
https://files.cnblogs.com/files/douzujun/stopwords.zip
直接手动下载 stopwords.zip
放到
然后,再执行之前的操作,就可以了
我们始终认为,如果靠手动建立环境不是长久之计,于是,找到了第二种方法
方法二:
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')
stop_words = nltk.corpus.stopwords.words('english')
print(len(stop_words))
print(stop_words[:7])
print([sw for sw in stop_words if len(sw) == 1])
执行结果 如下: