nltk安装punkt Resource punkt not found. Please use the NLTK Downloader to obtain the resource:

nltk安装punkt

##当调用nltk包的时候报错(已解决)

  Resource punkt not found.
  Please use the NLTK Downloader to obtain the resource:

  >>> import nltk
  >>> nltk.download('punkt')
  

完整报错如下

(base) @Mac data2text-transformer % python scripts/data_extract.py -d rotowire/train.json -o rotowire/train
Traceback (most recent call last):
  File "scripts/data_extract.py", line 486, in <module>
    summary_list = extract_summary(json_data, summary_key, entity_dict)
  File "scripts/data_extract.py", line 251, in extract_summary
    result_tokens = word_tokenize(' '.join(result), language='english')
  File "/Users/l/Downloads/中国软件杯/code/data2text-transformer/scripts/tokenizer.py", line 58, in word_tokenize
    tokenized = nltk.word_tokenize(string, language=language)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/tokenize/__init__.py", line 130, in word_tokenize
    sentences = [text] if preserve_line else sent_tokenize(text, language)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/tokenize/__init__.py", line 107, in sent_tokenize
    tokenizer = load("tokenizers/punkt/{0}.pickle".format(language))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/data.py", line 750, in load
    opened_resource = _open(resource_url)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/data.py", line 875, in _open
    return find(path_, path + [""]).open()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/data.py", line 583, in find
    raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
  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


解决方法:
方法一:按照提示在终端 进入python环境 然后
import nltk
nltk.download(‘punkt’)
#这个方法因为网络问题可能不行

方法二:根据它给的地址去下载punkt语料包,离线下载,然而404.
ps:我这里有百度云版本的
链接: https://pan.baidu.com/s/1wAOGoAnhvsuGnrZMvgXvSQ 提取码: nyng

下载后将它放在系统提示的文件夹下nltk安装punkt Resource punkt not found. Please use the NLTK Downloader to obtain the resource:_第1张图片
但是需要注意需要在上级目录下再建两个包nltk_data和tokenizers
nltk安装punkt Resource punkt not found. Please use the NLTK Downloader to obtain the resource:_第2张图片

然后再运行程序就ok了。

你可能感兴趣的:(python,深度学习)