Nltk import problems

流过昼夜 提交于 2019-12-24 19:15:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!