Elliot Lee Elliot Lee - 1 month ago 24
Python Question

ImportError: No module named 'nltk.tokenize'; 'nltk' is not a package

I am using python 3.5.2 within the pycharm IDE in windows 7, and I am having trouble importing the nltk package.

import nltk


gives the following error:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs)
File "C:\Python\nltk practice.py", line 7, in <module> from nltk.tokenize import sent_tokenize, word_tokenize
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'nltk.tokenize'; 'nltk' is not a package


nltk seems to be properly installed. When i run the following in the terminal

pip install nltk


I get:

Requirement already satisfied (use --upgrade to upgrade): nltk in c:\users\leee\appdata\local\programs\python\python35-32\lib\site-packages


When I run
PATH
in the terminal, or
sys.path
in the python console,

C:\Users\leee\AppData\Local\Programs\Python\Python35-32\Lib\site-packages
shows up within the long list. That is where all my other packages are installed, and other packages which are all importing properly.

I'm pretty confused right now, and all help is appreciated.

Answer

This usually happens because you have another file called nltk.py. Check your directory (C:\Python, where you are running this script) and remove or rename it if it's there. (I suppose the stray nltk.py might be somewhere else on your PYTHONPATH too.)