已解决Resource stopwords not found. Please use the NLTK Downloader to obtain the resource:

Solved (nltk loading stopwords database error) Resource stopwords not found.
Please use the NLTK Downloader to obtain the resource:







error code



A small friend in the fan group wanted to use nltk to load stop words, and an error occurred when copying someone else's code online (at that time, he felt a lot of cold in his heart, and came to me for help, and then successfully helped him solve it , by the way, I hope to help more friends who will not solve this bug), the error code is as follows:


from nltk.corpus import stopwords

stop_words = set(stopwords.words('english'))
print(stop_words)

We can see that he imports the package without any problems (the nltk module has been installed):

insert image description here


The content of the error message is as follows :

Traceback (most recent call last):
  File "D:\Python3.8\lib\site-packages\nltk\corpus\util.py", line 84, in __load
    root = nltk.data.find(f"{
      
      self.subdir}/{
      
      zip_name}")
  File "D:\Python3.8\lib\site-packages\nltk\data.py", line 583, in find
    raise LookupError(resource_not_found)
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\\Administrator/nltk_data'
    - 'D:\\Python3.8\\nltk_data'
    - 'D:\\Python3.8\\share\\nltk_data'
    - 'D:\\Python3.8\\lib\\nltk_data'
    - 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
**********************************************************************


error translation



Error message translation:

Could not find resource stopwords.

Please use the NLTK downloader to get the resources:



Reason for error



Reason for the error : The stop thesaurus will not be automatically installed when the nltk library is installed. You can install it manually in the following way. The blogger has already downloaded the thesaurus, and you can download it for free! ! !



Solution



At that time, I checked the information and learned that I could download this data myself. According to the error message, you can put it in any of the following directories (note: everyone's directory is not necessarily)


insert image description here



I created a nltk_data folder in the Python3.8 folder, created a corpora folder down, and finally put the decompressed folder of stopwords in the corpora folder: D:\Python3.8\nltk_data\corpora :

insert image description here

Run the program again to see that the stop word library is loaded:

insert image description here

The blogger has already downloaded three thesaurus commonly used by NLTK: stop thesaurus and part-of-speech thesaurus. . .Pay attention to the public account at the end of the article and reply: nltk_data, you can get it! ! !After downloading, put it under the specified file path of your own error message!

insert image description here


Pay attention to the public number at the end of the article and reply :nltk_data


insert image description here


help

This article has been included in: "Farewell to Bug" column

This column is used to record various difficult bugs encountered in study and work, as well as various problems raised by small partners in the fan group. Article format: error code + error translation + error reason + solution, including program installation, operation If you encounter other problems in the process of the program, if you encounter other problems after subscribing to the column + following the blogger, you can privately chat to help solve them! ! !

Guess you like

Origin blog.csdn.net/yuan2019035055/article/details/126407191