NLTK - No module named corpus
importerror, nltk, python
Solution
From your stacktrace: `File "nltk.py", line 1, in <module>`, you have called your file nltk.py. When python searches for a module, it looks in the current directory first, and you have "nltk.py" there. It will import this as nltk, and since your code does not define corpus, it can't find `nltk.corpus`.
To fix this, you should rename your file to something else, say `nltkexperience.py`. Also make sure to remove "nltk.pyc" from your directory if it exists, since this will also be loaded (it's the byte compiled version of your code). After that, it should work fine.
Problem
After installing NLTK and NLTK-DATA with PIP, i run python then i type from nltk.corpus import cmudict and it works. But when i wrote a script like this: ``` from nltk.corpus import cmudict d = cmudict.dict() def nsyl(word): return [len(list(y for y in x if y[-1].isdigit())) for x in d[word.lower()]] print nsyl("hello") ``` I have the following error : ``` Traceback (most recent call last): File "nltk.py", line 1, in <module> from nltk.corpus import cmudict File "nltk.py", line 1, in <module> from nltk.corpus import cmudict ImportError: No module named corpus ``` How can i fix this ? Thanks in advance