【python异常】安装NLTK库成功后导入库报错:LookupError:Resource punkt not found. import nltk nltk.download(‘punkt‘)

一、异常展示:

D:\CODEInterpreter\python3.6.8\python.exe D:/CODEFile/PythonCode01/PyTorch/ChatRobot/2/NLTK.py
[nltk_data] Error loading punkt: <urlopen error [Errno 11004]
[nltk_data]     getaddrinfo failed>
Traceback (most recent call last):
  File "D:/CODEFile/PythonCode01/PyTorch/ChatRobot/2/NLTK.py", line 7, in <module>
    tokens = nltk.word_tokenize(sentence)
  File "D:\CODEInterpreter\python3.6.8\lib\site-packages\nltk\tokenize\__init__.py", line 129, in word_tokenize
    sentences = [text] if preserve_line else sent_tokenize(text, language)
  File "D:\CODEInterpreter\python3.6.8\lib\site-packages\nltk\tokenize\__init__.py", line 106, in sent_tokenize
    tokenizer = load(f"tokenizers/punkt/{language}.pickle")
  File "D:\CODEInterpreter\python3.6.8\lib\site-packages\nltk\data.py", line 750, in load
    opened_resource = _open(resource_url)
  File "D:\CODEInterpreter\python3.6.8\lib\site-packages\nltk\data.py", line 876, in _open
    return find(path_, path + [""]).open()
  File "D:\CODEInterpreter\python3.6.8\lib\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/english.pickle

  Searched in:
    - 'C:\\Users\\Administrator/nltk_data'
    - 'D:\\CODEInterpreter\\python3.6.8\\nltk_data'
    - 'D:\\CODEInterpreter\\python3.6.8\\share\\nltk_data'
    - 'D:\\CODEInterpreter\\python3.6.8\\lib\\nltk_data'
    - 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - ''
**********************************************************************

二、异常出现原因

NLK是自然语言处理的官方库,Python上著名的自然语言处理库自带语料库,词性分类库自带分类,分词,等等功能。

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

没有找到 punkt 资源包。

  Searched in:
    - 'C:\\Users\\Administrator/nltk_data'
    - 'D:\\CODEInterpreter\\python3.6.8\\nltk_data'
    - 'D:\\CODEInterpreter\\python3.6.8\\share\\nltk_data'
    - 'D:\\CODEInterpreter\\python3.6.8\\lib\\nltk_data'
    - 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - ''

搜索 punkt 资源包 在这些路径下查找过,但是没有找到。
在这里插入图片描述

三、解决方案

3.1 下载punkt.zip

链接: https://pan.baidu.com/s/1H2qBy16qwLdDG_eTOQzlCg 提取码: rajj

3.2 新建目录 nltk_data

任意选取一个路径:
在这里插入图片描述
创建目录 nltk_data,进入nltk_data,创建子目录 tokennizers,解压压缩包
【注意路径的层次,否则会失败】
在这里插入图片描述

四、测试异常是否解决

在这里插入图片描述
异常已经解决OK!!!

  • 9
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值