简体   繁体   中英

Nltk import problems

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM