我在Macbook上安装了NLTK,在Macbook上安装了MacOS Mojave
/usr/local/share/nltk_data all
目录。
我已经使用
安装了它sudo pip install -U nltk
然后
sudo python -m nltk.downloader -d /usr/local/share/nltk_data all
但是我无法从任何其他目录的python中访问NLTK。
我得到了错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 129, in <module>
from nltk.collocations import *
File "/Library/Python/2.7/site-packages/nltk/collocations.py", line 38, in <module>
from nltk.util import ngrams
File "/Library/Python/2.7/site-packages/nltk/util.py", line 10, in <module>
import inspect
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 39, in <module>
import tokenize
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tokenize.py", line 31, in <module>
from token import *
File "token.py", line 1, in <module>
from nltk.tokenize import sent_tokenize, word_tokenize
File "/Library/Python/2.7/site-packages/nltk/tokenize/__init__.py", line 67, in <module>
from nltk.tokenize.mwe import MWETokenizer
File "/Library/Python/2.7/site-packages/nltk/tokenize/mwe.py", line 31, in <module>
from nltk.util import Trie
ImportError: cannot import name Trie`
我在Python 2.7上收到该错误。在Python3上,我得到
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nltk'
NLTK仅在我尝试从安装它的“ nltk_data”文件夹中调用时才起作用。我想从任何地方访问它。
有人可以帮我吗?
答案 0 :(得分:0)
尝试sudo -H pip3 install nltk --force-reinstall
,应该可以