ImportError: no module with the tag

I am working on an NLTK project, I have successfully installed it, following the tutorial here , I use Windows 7. Therefore, to help I test my installation, I ran these commands in python:

import nltk from nltk.tag import pos_tag 

I am using Python 2.7 and is located under C:\Python27 . Then I created a sample script ( D: \ nltk-test.py ) that contains the following commands:

 import nltk from nltk.tag import pos_tag text = nltk.word_tokenize("Hello world!") print pos_tag(text) 

The problem is when I tried to execute this with python nltk-test.py , I get an error

 Traceback (most recent call last): File "nltk-test.py", line 1, in <module> import nltk File "D:\nltk.py", line 3, in <module> ImportError: No module named tag 

I moved the file ( nltk-test.py ) inside C:\Python27\ and it works fine, but I cannot run it outside or if I placed it on another drive.

0
python nltk
source share
1 answer

In your D:// nltk.py is already present. When importing, imports this nltk.py file instead of the nltk module. There is no class, function, or tag variable in this nltk.py file. Therefore, why the import error.

Decision:

rename the nltk.py file to another. or move it to a different directory than your nltk-test.py directory.

+1
source share

All Articles