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_data和tokenizers
在这里插入图片描述

然后再运行程序就ok了。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值