Skip to content
Advertisement

Resource reuters not found

I’m using windows system, python 3.7 when I install:

import nltk
nltk.download('reuters')

it has no problem to import, and I also already install nltk in my cmd

but when I conduct the code:

import matplotlib.pyplot as plt
from collections import Counter
from nltk.corpus import reuters
import re
import spacy
nlp = spacy.load('en', disable=['parser', 'tagger'])
reuters_fileids = reuters.fileids()  
reuters_nlp = [nlp(re.sub('s+',' ', reuters.raw(i)).strip()) for i in reuters_fileids[:100]]
label_counter = Counter()

it has some Error, and I don’t know how to fix it… However, the code works well on my MacBook I’m wondering what’s going on with the windows system p.s I use anaconda, and on the windows computer, the anaconda is installed on E:

Resource reuters not found.
  Please use the NLTK Downloader to obtain the resource:

  >>> import nltk
  >>> nltk.download('reuters')

  Searched in:
    - 'C:\Users\user/nltk_data'
    - 'C:\nltk_data'
    - 'D:\nltk_data'
    - 'E:\nltk_data'
    - 'E:\Anaconda\nltk_data'
    - 'E:\Anaconda\share\nltk_data'
    - 'E:\Anaconda\lib\nltk_data'
    - 'C:\Users\user\AppData\Roaming\nltk_data'

Advertisement

Answer

You don’t have the corpus in your new environment.

Download the corpus as suggested in the error message:

>>> from nltk.corpus import reuters

>>> import nltk
>>> nltk.download('reuters')
[nltk_data] Downloading package reuters to
[nltk_data]     /Users/liling.tan/nltk_data...
True

>>> reuters.words()
['ASIAN', 'EXPORTERS', 'FEAR', 'DAMAGE', 'FROM', 'U', ...]
>>> reuters.sents()
[['ASIAN', 'EXPORTERS', 'FEAR', 'DAMAGE', 'FROM', 'U', '.', 'S', '.-', 'JAPAN', 'RIFT', 'Mounting', 'trade', 'friction', 'between', 'the', 'U', '.', 'S', '.', 'And', 'Japan', 'has', 'raised', 'fears', 'among', 'many', 'of', 'Asia', "'", 's', 'exporting', 'nations', 'that', 'the', 'row', 'could', 'inflict', 'far', '-', 'reaching', 'economic', 'damage', ',', 'businessmen', 'and', 'officials', 'said', '.'], ['They', 'told', 'Reuter', 'correspondents', 'in', 'Asian', 'capitals', 'a', 'U', '.', 'S', '.', 'Move', 'against', 'Japan', 'might', 'boost', 'protectionist', 'sentiment', 'in', 'the', 'U', '.', 'S', '.', 'And', 'lead', 'to', 'curbs', 'on', 'American', 'imports', 'of', 'their', 'products', '.'], ...]

Alternatively, you can also download the corpus from command line:

$ python3 -m nltk.downloader reuters
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py:125: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
[nltk_data] Downloading package reuters to
[nltk_data]     /Users/liling.tan/nltk_data...
[nltk_data]   Package reuters is already up-to-date!

See also: How do I download NLTK data?

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement