python nltk 安装及配置说明

本教程采用pip安装方式,前期需要在本机安装setuptools 及pip

网上铺天盖地的说了很多关于nltk的说明,特别是后期nltk_data 手动下载操作,多数都不好使,这里整理

用pip安装nltk , 运行pip install nltk,等一段时间安装完成以后。进入IDLE界面(可以通过windows搜索栏查找,这是python的终端)敲入下面两行代码:

import nltk  
nltk.download()   
  
   随后弹出下面界面(坚持,离成功不远了)
 
  

选择第三项book,然后等待下载安装完成即可。如果由于网络等原因造成无法下载也可以到http://nltk.org/nltk_data/ 来手动下载。

如果手动指定了nltk_data的保存目录,需要添加环境变量
  手动下载的nltk_data-gh-pages包中,真正需要的是该文件夹中的packages,将此文件夹重命名为nltk_data,并添加此目录到系统环境变量
否则会报错:
错误

检测nltk_data是否安装成功:

输入:from nltk.book import  *

   >>> from nltk.book import  *
   输出:
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
 
按照如上方法即可完成nltk的全部安装,希望对大家有帮助!
 
原文地址:https://www.cnblogs.com/fclbky/p/7920810.html