在 MACOS 上安装 NLTK

我正在尝试使用 Mac OS Mojave 在我的 2015 Mac Pro 上安装 NLTK。


我用了


sudo pip install nltk

它下载了安装文件并成功安装。


当我进入 python 并输入时


nltk.download()

我明白了


NLTK Downloader

---------------------------------------------------------------------------

d) Download   l) List    u) Update   c) Config   h) Help   q) Quit

---------------------------------------------------------------------------

Downloader>

使用“d”后,它下载了一些包和模块。


但是,当我尝试运行它时,我无法使用 nltk


from nltk.tokenize import sent_tokenize, word_tokenize

data = "All work and no play makes jack dull boy. All work and no play makes jack a dull boy."

print(sent_tokenize(data))

这给了我一个错误说:


File "token.py", line 1, in <module>

from nltk.tokenize import sent_tokenize, word_tokenize

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 "/Users/Documents/NLTK/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

请帮忙!


子衿沉夜
浏览 268回答 1
1回答

繁星淼淼

转到python控制台并输入nltk.download('all')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python