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.
source share