Comment #1 on issue 374 by StevenBird1: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374
(No comment was entered for this change.)
I think what causes this is that, when decorators.py imports "inspect",
inspect then imports "tokenize".
But when you're in this directory, "tokenize" refers to NLTK's tokenize,
not Python's tokenize.
I the error go away by temporarily removing NLTK's tokenize directory. Is
there a way to make sure that NLTK's tokenize doesn't conflict with Python
standard library code trying to import Python's "tokenize", short of
renaming the NLTK module?
I agree with this diagnosis. I wonder why "import tokenize" inside the
inspect module finds nltk.tokenize. Perhaps this is a case of implicit
relative imports. How can we avoid this?
http://docs.python.org/tutorial/modules.html#intra-package-references
It can be fixed with a pretty simple hack that takes out the "nltk"
directory from sys.path before we try to import "tokenize".
Is this too ham-fisted? (if it's OK, I'll go ahead and check it in.)
Attachments:
fix_decorators_r8704.patch 564 bytes
Does this work? I think the inspect module picks up nltk.tokenize via the
implicit relative import mechanism: "the import statement first looks in
the containing package before looking in the standard module search path".
Removing nltk from sys.path should have no effect on "import tokenize", but
only on "from nltk import tokenize" and on "import nltk.tokenize".
It does work; and I think you're right about the implicit relative import
being why nltk's tokenize gets picked up.
It's just that when you execute python nltk/decorators.py, the nltk
directory is now in the module path. Printing out sys.path before changing
it (for me) gives...
path:
['/home/alex/checkouts/nltk-trunk/nltk/nltk', '/usr/lib/python2.6', ...]
That first entry is the location of decorators.py.
I see. Alright please go ahead and apply that patch and close this issue,
thanks.
Comment #8 on issue 374 by alex.rudnick: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374
OK, committed the patch at r8706.
Thanks for taking a look, Steven!