3

I have a windows 7 64 bit machine and just installed the 64 bit version of python 3.5 and the nltk package (which I downloaded as a .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#nltk and pip installed from the windows command prompt). I've also downloaded all the corpora and other data associated with nltk.

In python IDLE I am able to import nltk and the brown corpus all right, but when I try to examine some words in the Brown corpus I get an AttributeError ("can't set attribute"). Here is my code:

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

It is the last line which generates the error. The error message is several lines long so will not include all of it here. The last line of the error is: AttributeError: can't set attribute.

I have experience in R and Matlab but I am completely new to python and have no idea what to do.

EDIT: Here is the full error text

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
ben
  • 787
  • 3
  • 16
  • 32
  • Your exception was actually exactly what was needed. I ran this on my end, and the error message lead me here: http://stackoverflow.com/questions/13965823/resource-corpora-wordnet-not-found-on-heroku – idjaw Oct 09 '15 at 15:10
  • @idjaw What do you mean by "exception?" And "needed" by whom? The link you post seems to address a "File Not Found" situation, when what I have here is an AttributeError. – ben Oct 09 '15 at 18:46
  • An AttributeError is a type of exception. And by needed I implied that it was something that would have been helpful to provide in your original post. I did a quick search of the exception that was raised when I ran your code and that is what came up. I apologize if it wasn't helpful. – idjaw Oct 09 '15 at 18:49
  • @idjaw I edited my question to include the full error text. – ben Oct 09 '15 at 19:13
  • @idjaw I wrote to python support and they say the problem is probably [this nltk bug](https://github.com/nltk/nltk/issues/1106) – ben Oct 12 '15 at 02:05
  • @Valent, NLTK version 3.1 is out and it has fixed this bug. PS. Please consider writing a self-answer, since others are likely to have the same problem. – alexis Oct 16 '15 at 22:13

0 Answers0