如何解决 NLTK LookupError(resource_not_found) ?它存在于路径中。 (Python)

How to solve NLTK LookupError(resource_not_found) ? It exists in path. (Python)

我尝试使用 nltk 库,但卡住了。 我手动下载了停用词库(由于我工作机器上的权限问题,我无法通过代码下载),但它总是给我以下错误;

LookupError: 
**********************************************************************
  Resource stopwords not found.
  Please use the NLTK Downloader to obtain the resource:
....
Searched in:
  - '/home/skahraman/nltk_data'
....

我的停用词在 nltk_data 文件夹中。 那么我该如何解决这个问题呢?

我尝试关注;

import string
import nltk
from nltk import word_tokenize
from nltk.corpus import stopwords
from collections import Counter
#nltk.download('stopwords')
nltk.data.path.append("/home/skahraman/nltk_data")
stop_words=stopwords.words("turkish")

您似乎没有正确地为 nlkt.data module. I also noticed a very similar issue 分配文件路径,请尝试使用 tempfile.gettempdir 指定路径并下载它。

import tempfile
import string
import nltk
from nltk import word_tokenize
from nltk.corpus import stopwords
from collections import Counter

download('stopwords', download_dir=tempfile.gettempdir())
nltk.data.path.append(tempfile.gettempdir())
stop_words=stopwords.words("turkish")

我的文件夹路径是; /home/skahraman/nltk_data/stopwords

但必须是; /home/skahraman/nltk_data/corpora/stopwords

我将语料库文件夹添加到我的目录中。 所以它现在可以工作了。