Reputation: 181
I am new in NLP (Natural Language Processing)
, I have installed NLTK
on my computer and I have downloaded all the packages using nltk.download()
My Script
from nltk.tokenize import sent_tokenize
example_text = "Hello Mr. Shan, how are you doing? the weather is quite cool today in Guwahati. I heard you are going to Delhi tomorrow."
print(sent_tokenize(example_text))
Error
C:\wamp64\www\python\NLTK>python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from nltk.tokenize import sent_tokenize
File "C:\Python27\lib\site-packages\nltk\__init__.py", line 129, in <module>
from nltk.collocations import *
File "C:\Python27\lib\site-packages\nltk\collocations.py", line 38, in <module
>
from nltk.util import ngrams
File "C:\Python27\lib\site-packages\nltk\util.py", line 10, in <module>
import inspect
File "C:\Python27\lib\inspect.py", line 39, in <module>
import tokenize
File "C:\wamp64\www\python\NLTK\tokenize.py", line 1, in <module>
"""Tokenization help for Python programs.
File "C:\Python27\lib\site-packages\nltk\tokenize\__init__.py", line 67, in <m
odule>
from nltk.tokenize.mwe import MWETokenizer
File "C:\Python27\lib\site-packages\nltk\tokenize\mwe.py", line 31, in <module
>
from nltk.util import Trie
ImportError: cannot import name Trie
Upvotes: 3
Views: 2454
Reputation: 21
I can see that your script is named test.py, but I'm wondering if at any point you created a tokenize.py file? Try removing any tokenize.pyc and renaming any tokenize.py file. I had this same issue just now. Upon renaming the file it worked.
Also note that you will have to import nltk before being able to call from nltk.
Reference: cannot import name defaultdict error for nltk
Upvotes: 2