jupyterhub - NLTK - 无法使用停用词 - 找不到资源停用词

jupyterhub - NLTK - unable to use stopwords - Resource stopwords not found

我正在使用以下代码通过 jupyter notebook 使用停用词。我在 Linux 服务器上托管了 jupyter 并使用笔记本。

python3 -m nltk.downloader stopwords
python3 -m nltk.downloader words
python3 -m nltk.downloader punkt

python3
>>>from nltk.corpus import stopwords
>>>stop_words = set(stopwords.words("english"))
>>>print(stop_words)

这在 运行 在 python 终端中工作正常,但是当我在 Jupyternotebook 中尝试下面时它失败并出现错误。

from nltk.corpus import stopwords
stop_words = set(stopwords.words("english"))
print(stop_words)

---------------------------------------------------------------------------
LookupError                               Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/nltk/corpus/util.py in __load(self)
     82                 try:
---> 83                     root = nltk.data.find("{}/{}".format(self.subdir, zip_name))
     84                 except LookupError:

/usr/local/lib/python3.7/site-packages/nltk/data.py in find(resource_name, paths)
    582     resource_not_found = "\n%s\n%s\n%s\n" % (sep, msg, sep)
--> 583     raise LookupError(resource_not_found)
    584 

LookupError: 
**********************************************************************
  Resource stopwords not found.
  Please use the NLTK Downloader to obtain the resource:

在 jupyter notebook 中尝试 运行

import nltk 
nltk.download('stopwords')