当前位置:   article > 正文

手动安装Python自然语言工具包NLTK_nltk安装包

nltk安装包

在尝试用官方的安装方式几次失败后,发现官方的这种方式真的很坑。于是上网按着大家的教程,终于摸索出了一个可行的方法。

安装

首先下载nltk安装包:

官方下载网址

github下载地址1

github下载地址2

解压

下载完成后,将文件解压放在D盘根目录。

测试

然后打开IDE进行测试:

from nltk.book import *

输出结果:

  1. *** Introductory Examples for the NLTK Book ***
  2. Loading text1, ..., text9 and sent1, ..., sent9
  3. Type the name of the text or sentence to view it.
  4. Type: 'texts()' or 'sents()' to list the materials.
  5. text1: Moby Dick by Herman Melville 1851
  6. text2: Sense and Sensibility by Jane Austen 1811
  7. text3: The Book of Genesis
  8. text4: Inaugural Address Corpus
  9. text5: Chat Corpus
  10. text6: Monty Python and the Holy Grail
  11. text7: Wall Street Journal
  12. text8: Personals Corpus
  13. text9: The Man Who Was Thursday by G . K . Chesterton 1908

到这里,说明nltk库已经安装好了,但是在编程测试的时候,仍然报错:

  1. from nltk import word_tokenize
  2. from nltk import Text
  3. tokens = word_tokenize("Here is some not very interesting text")
  4. text = Text(tokens)
  5. print(text)

错误1:punkt没找到

解决方案:

1、打开路径:D:\nltk_data\tokenizers,发现有一个名为<punkt.zip>的压缩包;

2、选中该压缩包,解压到当前目录下

再次运行上述程序,又报错,错误为:D:\nltk_data\tokenizers\punkt\PY3\english.pickle没找到

解决方案:

1、打开路径D:\nltk_data\tokenizers\punkt,发现其实存在english.pickle

2、路径检索的时候多了个\PY3\,所以,在D:\nltk_data\tokenizers\punkt新建一下文件夹,命名为PY3,然后将文件english.pickle拷贝进去PY3文件夹下

再次运行程序,结果正确:

<Text: Here is some not very interesting text...>

总结

如果在运行程序时,提示说没有找到某个文件,那么可以去该路径下查看,是否没有解压文件,或者路径不对。

按照提示路径创建文件即可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/633104
推荐阅读
相关标签
  

闽ICP备14008679号