After installing NLTK and NLTK-DATA with PIP, I start python , then I type import cmudict from nltk.corpus and it works. But when I wrote the script as follows:
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
From your stacktrace:, File "nltk.py", line 1, in <module>you called the nltk.py file. When python is looking for a module, it first looks in the current directory, and you have "nltk.py". It will import this as nltk, and since your code does not define corpus, it cannot find it nltk.corpus.
File "nltk.py", line 1, in <module>
nltk.corpus
, , nltkexperience.py. "nltk.pyc" , , ( ). .
nltkexperience.py
, , -, . Python, , , NLTK, , script.
Python 2.7, Python 3.3 Anaconda Python (2.7). Anaconda ( , ). , - pip , . Vim Python, / Anaconda. Vim Python, , .
, .
Source: https://habr.com/ru/post/1547286/More articles:Why forcing a null string to a null string - javaOnsubmit form is completely ignored - javascriptChoosing Sorting in Daphne - sortingGetting Android NDK r9d to Support C ++ 11 - c ++Search for contextual keywords with Roslyn - c #Finding the best match for strings with R - stringBlur SKShapeNode with SKEffectNode - iosHow to determine Unicode version in PHP and PCRE? - phpangular-bootstrap accordion binding question - javascriptIs there a difference in the JSON Key when using a single quote and a double quote? - jsonAll Articles