调用nltk时的Python AttributeError布朗语料库

时间:2015-10-09 15:06:30

标签: python python-3.x nltk

我有一台Windows 7 64位机器,刚刚安装了64位版本的python 3.5和nltk软件包(我从http://www.lfd.uci.edu/~gohlke/pythonlibs/#nltk下载了.whl文件,并从windows命令提示符下安装了pip)。我还下载了与nltk相关的所有语料库和其他数据。

在python IDLE中我可以直接导入nltk和棕色语料库,但是当我尝试检查布朗语料库中的某些单词时,我得到一个AttributeError("不能设置属性" )。这是我的代码:

    >>> import nltk
    >>> from nltk.corpus import brown
    >>> brown.words()

这是生成错误的最后一行。错误消息是几行,所以这里不包括所有。错误的最后一行是:AttributeError:无法设置属性。

我有R和Matlab的经验,但我对python完全不熟悉,不知道该怎么做。

编辑:这是完整的错误文本

Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
brown.words()
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\idlelib\rpc.py", line 611, in displayhook
text = repr(value)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\util.py", line 664, in __repr__
for elt in self:
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\corpus\reader\util.py", line 394, in iterate_from
for tok in piece.iterate_from(max(0, start_tok-offset)):
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\corpus\reader\util.py", line 291, in iterate_from
tokens = self.read_block(self._stream)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\corpus\reader\tagged.py", line 243, in read_block
for sent_str in self._sent_tokenizer.tokenize(para_str):
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tokenize\regexp.py", line 126, in tokenize
self._check_regexp()
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tokenize\regexp.py", line 121, in _check_regexp
self._regexp = compile_regexp_to_noncapturing(self._pattern, self._flags)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\internals.py", line 56, in compile_regexp_to_noncapturing
return sre_compile.compile(convert_regexp_to_noncapturing_parsed(sre_parse.parse(pattern)), flags=flags)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\internals.py", line 52, in convert_regexp_to_noncapturing_parsed
parsed_pattern.pattern.groups = 1
AttributeError: can't set attribute

0 个答案:

没有答案