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

I am using python 3.5.2 inside the pycharm IDE on Windows 7 and I am unable to import 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 installed correctly. When i run in terminal

following:
 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 terminal or sys.path in python console,

C:\Users\leee\AppData\Local\Programs\Python\Python35-32\Lib\site-packages appears in a long list. This is where all my other packages and other packages are installed, which all are imported properly.

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

+5
source share
3 answers

This usually happens because you have another file called nltk.py Check your directory ( C:\Python , where you use this script), and delete or rename it, if any. (I suppose the wandering nltk.py might be somewhere else on your PYTHONPATH .)

+8
source

In pycharm, press ctrl / cmd + shift + A , then type "Python Interpreter"

and make sure you have the same interpreter as the one referenced by pip (and not the default one Jetbrains)

Note. If you have both python 2.7 and python 3.x installed, the convention is that pip refers to 2.x dist and pip3 refers to 3.x

+1
source

Thanks. He solved my problem.

Problem: I created the file "nltk.py" and wrote the code in this file and tried to execute it, indicating the error "ModuleNotFoundError: There is no module named" nltk.tokenize "; 'nltk' is not a package '.

Solution: After that I renamed "nltk.py" to some other, then my problem was solved.

+1
source

Source: https://habr.com/ru/post/1259100/


All Articles