其他分享
首页 > 其他分享> > 解决:Resource stopwords not found.

解决:Resource stopwords not found.

作者:互联网

解决:Resource stopwords not found.

报错如下

---------------------------------------------------------------------------
LookupError                               Traceback (most recent call last)
E:\Users\TFX\Anaconda3\envs\tensorflow24\lib\site-packages\nltk\corpus\util.py in __load(self)
     82                 try:
---> 83                     root = nltk.data.find("{}/{}".format(self.subdir, zip_name))
     84                 except LookupError:

E:\Users\TFX\Anaconda3\envs\tensorflow24\lib\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:

  >>> import nltk
  >>> nltk.download('stopwords')
  
  For more information see: https://www.nltk.org/data.html

  Attempted to load corpora/stopwords.zip/stopwords/

  Searched in:
    - 'C:\\Users\\TFX/nltk_data'
    - 'E:\\Users\\TFX\\Anaconda3\\envs\\tensorflow24\\nltk_data'
    - 'E:\\Users\\TFX\\Anaconda3\\envs\\tensorflow24\\share\\nltk_data'
    - 'E:\\Users\\TFX\\Anaconda3\\envs\\tensorflow24\\lib\\nltk_data'
    - 'C:\\Users\\TFX\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
**********************************************************************


During handling of the above exception, another exception occurred:

LookupError                               Traceback (most recent call last)
<ipython-input-3-c87583f8fb10> in <module>
      5 from tensorflow.keras.preprocessing.sequence import pad_sequences
      6 from nltk.corpus import stopwords
----> 7 STOPWORDS = set(stopwords.words('english'))

E:\Users\TFX\Anaconda3\envs\tensorflow24\lib\site-packages\nltk\corpus\util.py in __getattr__(self, attr)
    118             raise AttributeError("LazyCorpusLoader object has no attribute '__bases__'")
    119 
--> 120         self.__load()
    121         # This looks circular, but its not, since __load() changes our
    122         # __class__ to something new:

E:\Users\TFX\Anaconda3\envs\tensorflow24\lib\site-packages\nltk\corpus\util.py in __load(self)
     83                     root = nltk.data.find("{}/{}".format(self.subdir, zip_name))
     84                 except LookupError:
---> 85                     raise e
     86 
     87         # Load the corpus.

E:\Users\TFX\Anaconda3\envs\tensorflow24\lib\site-packages\nltk\corpus\util.py in __load(self)
     78         else:
     79             try:
---> 80                 root = nltk.data.find("{}/{}".format(self.subdir, self.__name))
     81             except LookupError as e:
     82                 try:

E:\Users\TFX\Anaconda3\envs\tensorflow24\lib\site-packages\nltk\data.py in find(resource_name, paths)
    581     sep = "*" * 70
    582     resource_not_found = "\n%s\n%s\n%s\n" % (sep, msg, sep)
--> 583     raise LookupError(resource_not_found)
    584 
    585 

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

  >>> import nltk
  >>> nltk.download('stopwords')
  
  For more information see: https://www.nltk.org/data.html

  Attempted to load corpora/stopwords

  Searched in:
    - 'C:\\Users\\TFX/nltk_data'
    - 'E:\\Users\\TFX\\Anaconda3\\envs\\tensorflow24\\nltk_data'
    - 'E:\\Users\\TFX\\Anaconda3\\envs\\tensorflow24\\share\\nltk_data'
    - 'E:\\Users\\TFX\\Anaconda3\\envs\\tensorflow24\\lib\\nltk_data'
    - 'C:\\Users\\TFX\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
**********************************************************************

解决方法

python
>>> import nltk
>>> nltk.download('stopwords')

在这里插入图片描述

标签:Resource,Users,envs,stopwords,TFX,tensorflow24,found,data,nltk
来源: https://blog.csdn.net/FriendshipTang/article/details/116862005