【发布时间】:2016-06-14 21:51:46
【问题描述】:
我正在使用此脚本尝试从 nltk 包中导入 twitter_samples for python。我目前在 Anaconda 环境中使用 python 2.7。
我正在使用 Spyder 运行代码。
import nltk
nltk.download('twitter_samples')
from nltk.corpus import twitter_samples
print twitter_samples.fileid()
当我运行它时,我得到了这个作为回报:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Person\Anaconda3\envs\py27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Users\Person\Anaconda3\envs\py27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/Ben/Anaconda3/attemptNLTK_download.py", line 9, in <module>
from nltk.corpus import twitter_samples
ImportError: cannot import name twitter_samples
但是当我导入 movie_reviews 时它工作正常。
from nltk.corpus import movie_reviews
我真的不知道为什么这不起作用。我按照建议在我的系统中为 NLTK_DATA 添加了一个环境变量作为 C:\nltk_data ,但这并没有解决它。它位于默认位置(C:\nltk_data)。
也许有一种方法可以直接“导入”语料库而不使用导入...数据在我的 C 驱动器上,我可以看到它,但我无法通过导入功能访问它。
我正在尝试使用这些数据来训练一个分类器来识别正面/负面的陈述/推文。
【问题讨论】:
标签: python python-2.7 twitter nltk spyder