栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

文章目录
    • 一、异常展示:
    • 二、异常出现原因
    • 三、解决方案
      • 3.1 下载`punkt.zip`
      • 3.2 新建目录 nltk_data
    • 四、测试异常是否解决

一、异常展示:
D:CODEInterpreterpython3.6.8python.exe D:/CODEFile/PythonCode01/PyTorch/ChatRobot/2/NLTK.py
[nltk_data] Error loading punkt: 
Traceback (most recent call last):
  File "D:/CODEFile/PythonCode01/PyTorch/ChatRobot/2/NLTK.py", line 7, in 
    tokens = nltk.word_tokenize(sentence)
  File "D:CODEInterpreterpython3.6.8libsite-packagesnltktokenize__init__.py", line 129, in word_tokenize
    sentences = [text] if preserve_line else sent_tokenize(text, language)
  File "D:CODEInterpreterpython3.6.8libsite-packagesnltktokenize__init__.py", line 106, in sent_tokenize
    tokenizer = load(f"tokenizers/punkt/{language}.pickle")
  File "D:CODEInterpreterpython3.6.8libsite-packagesnltkdata.py", line 750, in load
    opened_resource = _open(resource_url)
  File "D:CODEInterpreterpython3.6.8libsite-packagesnltkdata.py", line 876, in _open
    return find(path_, path + [""]).open()
  File "D:CODEInterpreterpython3.6.8libsite-packagesnltkdata.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!!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/846344.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号