问题
I can import ntlk and the pos_tag in the python shell just fine like so.
>>> import nltk
>>> from nltk import pos_tag
But when I need to write a script like
import nltk
from nltk import pos_tag
I get a traceback error
Traceback (most recent call last):
File "mynltkfile.py", line 1, in <module>
from nltk import pos_tag
File "/Users/jacksongeller/Desktop/nltktest/mynltkfile.py", line 1, in <module>
from nltk import pos_tag
ImportError: cannot import name pos_tag
I have already done nltk.download() and have downloaded everything. I have also piped numpy
Also if I just import nltk from a script, I get the same traceback
Traceback (most recent call last):
File "mynltkfile.py", line 1, in <module>
import nltk
File "/Users/jacksongeller/Desktop/nltktest/mynltkfile.py", line 1, in <module>
from nltk import pos_tag
ImportError: cannot import name pos_tag
Am I missing a file? If so where should it go? Thanks in advance
回答1:
From the interpreter, type
import nltk
import sys
print(nltk)
print(sys.executable)
and then create a script with the same contents and run
python script.py
Please post the output.
来源:https://stackoverflow.com/questions/19233967/nltk-import-problems