Python, ImportError: cannot import the name AbstractLazySequence

I am using nltk, but the problem I am facing is apparently not related to nltk. I have a module called util.tokenize , inside which there are some classes, and I have the following first line:

Util / tokenizer.py

 from nltk.tokenize.regexp import RegexpTokenizer ... class SentTokenizer(object): def __init__(self, stem=False, pattern='[^\w\-\']+'): self.alg = RegexpTokenizer(pattern, gaps=True) def __call__(self, text): return self.alg.tokenize(text) .... if __name__ == '__main__': s_t = SentTokenizer() s_t('blah blah') 

When I call these classes from another module, say test.py everything seems to work, but starting the tokenize.py module directly raises ImportError.

 File "tokenize.py", line 1, in <module> ... File "Python27\lib\site-packages\nltk\corpus\reader\util.py", line 28, in <module> from nltk.util import AbstractLazySequence, LazySubsequence, LazyConcatenation, py25 ImportError: cannot import name AbstractLazySequence 

What could be the problem? Why does this work when called from other modules?

test.py

 from util.tokenize import SentTokenizer s_t = SentTokenizer() print s_t('blah blah') 

The platform is Windows.

+5
source share
1 answer

We have determined that this is caused by a namespace conflict with nltk.tokenize and the user tokenize.py . After renaming tokenize.py everything worked correctly.

+4
source

All Articles