【问题标题】:jupyterhub - NLTK - unable to use stopwords - Resource stopwords not foundjupyterhub - NLTK - 无法使用停用词 - 找不到资源停用词
【发布时间】:2021-07-22 21:19:43
【问题描述】:

我正在使用以下代码通过 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:

【问题讨论】:

    标签: python nltk jupyter stop-words jupyterhub


    【解决方案1】:

    尝试在 jupyter notebook 中运行

    import nltk 
    nltk.download('stopwords')
    

    【讨论】:

    • @imdevaskp - 当我尝试在 python3 终端中下载时,我看到它已经是最新的了。>>> import nltk >>> nltk.download('stopwords') [nltk_data] Downloading package stopwords to /root/nltk_data... [nltk_data] Package stopwords is already up-to-date! 但是当通过 jupyter hub 尝试下载时超时。理想情况下,如果它是最新的,则不需要下载。那么 jupyter hub 中是否有配置来处理这个问题。
    猜你喜欢
    • 2021-07-26
    • 1970-01-01
    • 2022-10-25
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2017-01-21
    • 2014-05-10
    相关资源
    最近更新 更多