How to install nltk stopwords packages manually

Viewed 7237

This is my code:

from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

example_sent = "This is a sample sentence, showing off the stop words filtration."

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

word_tokens = word_tokenize(example_sent)

filtered_sentence = [w for w in word_tokens if not w in stop_words]

filtered_sentence = []

for w in word_tokens:
    if w not in stop_words:
        filtered_sentence.append(w)


print(word_tokens)
print(filtered_sentence)

But when running the code, I am getting this error:

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

If I download the NLTK Downloader, I am getting the below error:

[nltk_data] Error loading popular: <urlopen error [WinError 10054] An
[nltk_data]     existing connection was forcibly closed by the remote
[nltk_data]     host>

Can anyone tell me how to get rid of this error?

2 Answers

Does this work?

import nltk
nltk.download('stopwords')
Related