0
点赞
收藏
分享

微信扫一扫

【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!!!

举报

相关推荐

0 条评论