我正在尝试在Mac OSX 10.9上安装NLTK数据。要设置的下载目录,如NLTK3.0文档中所述,是用于中央安装的/usr/share/nltk_数据。但是对于这条路径,我得到了错误
oserror:[errno 13]权限被拒绝:“/usr/share/nltk\u data”
我可以将下载目录设置为/users/ananya/nltk_data进行集中安装吗?
我的机器上安装了python 2.7
谢谢,
阿尼亚尼亚
最佳答案
您是否尝试过:
$ sudo python
>>> import nltk
>>> nltk.download()
要检查下载是否有效,请尝试下载一些语料库,例如
>>> from nltk.corpus import wordnet
>>> wordnet.synsets('dog')
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]
如果语料库安装不正确,您将看到如下内容:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py", line 68, in __getattr__
self.__load()
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py", line 56, in __load
except LookupError: raise e
LookupError:
**********************************************************************
Resource 'corpora/wordnet' not found. Please use the NLTK
Downloader to obtain the resource: >>> nltk.download()
Searched in:
- '/home/alvas/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
**********************************************************************