我在mac上安装了nltk。下面是我使用nltk-word_tokesize函数的简单代码。我犯了这个错误。请告知!
import nltk
sentence = "I kN2ow Y1Ou."
s = sentence.lower()
words = nltk.word_tokenize(s)
print(words)
错误:
**********************************************************************
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('punkt')
For more information see: https://www.nltk.org/data.html
Attempted to load tokenizers/punkt/PY3/english.pickle
Searched in:
- '/Users/moeheinag/nltk_data'
- '/Library/Frameworks/Python.framework/Versions/3.8/nltk_data'
- '/Library/Frameworks/Python.framework/Versions/3.8/share/nltk_data'
- '/Library/Frameworks/Python.framework/Versions/3.8/lib/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- ''
**********************************************************************
所以我只是在终端上运行:
import nltk
nltk.download('punkt')
并收到此错误:
[nltk_data] Error loading punkt: <urlopen error [SSL:
[nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed:
[nltk_data] unable to get local issuer certificate (_ssl.c:1124)>
False
您需要按照的说明下载punkt
模块
在mac上打开Terminal
,执行-python
,然后执行以下命令
nltk
使用预先训练的单词和句子标记器,需要单独下载
>>> import nltk
>>> nltk.download('punkt')
如果下载失败,请使用以下内容,参考
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download()