NLTK数据安装问题

时间:2014-03-05 07:46:55

标签: python nltk

我正在尝试在Mac OSX 10.9上安装NLTK数据。如NLTK 3.0文档中所述,要设置的下载目录是/ usr / share / nltk_data,用于集中安装。但是对于这条路,我得到了错误 OSError:[Errno 13]权限被拒绝:'/ usr / share / nltk_data'

我可以将下载目录设置为/ Users / ananya / nltk_data进行集中安装吗?

我的机器上安装了Python 2.7

谢谢, 专一

1 个答案:

答案 0 :(得分: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'
**********************************************************************