1 安装
开发环境:windows 7 64位 + 32 Python 2.7.12位
声明一下:由于NLTK的官方网页给出的安装步骤中提到“Install Python 3.4: http://www.python.org/ downloads (avoid the 64-bit versions)”,即告诉大家别下载64位的python,因此我使用的是32位3.3.2版本。
1 安装python,安装路径为D:\mysoftware\Python27,并配置环境变量
在path后面加上: ;D:\mysoftware\Python27
2 安装Numpy,下载对应python 3.3版本的,我下载的是numpy-1.9.2-win32-superpack-python2.7.exe
3 安装pip
pip用来安装后续的包,安装pip前需确认已安装Python和easy_install。
如果成功装了python,则easy_install在Python安装目录下的scripts文件夹下,如,D:\mysoftware\Python27\Scripts。
进入Python安装目录下的Scripts路径,执行
easy_install.exe pip
出现下图,说明pip安装成功。
查看pip版本,输入pip --version,回车出现:
pip 8.1.1 from d:\mysoftware\python27\lib\site-packages (python 2.7)
把pip路径 加入环境变量path后面,这样可以直接从cmd 找到。
4 安装nltk
利用pip安装:
pip install nltk
5 安装PyYAML
pip install PyYAML
7这些都安装好,然后运行Python的IDE环境:
然后,Python Launcher会弹出下面这个界面,建议你选择安装所有的Packages,以免去日后一而再、再而三的进行安装,也为你的后续开发提供一个稳定的环境。某些包的Status显示“out of date”,你可以不必理会,它基本不影响你的使用与开发。
修改下载目录,点击download下载,下载速度很慢,有时候还会报错。
最好的方法是用使用@V_can打包好的的包网盘下载
下载地址1:https://pan.baidu.com/s/1slP4wfr
云盘密:znx7
下载地址2:https://pan.baidu.com/share/init?shareid=100987267&uk=2720665201
云盘密码:4cp3
有两种方法加入这些数据。
方法1:nltk_data.zip 解压到python根目录下:
方法2:自己放一个路径,配置环境变量NLTK_DATA
2 NLTK测试
测试环境是否安装好请按照下列步骤(全部在python console中完成,就是输入一行输出一行的那种IDE):
In[4]:from nltk.book import *
# 只输入import nltk 会出错的,但却有很多博客上都这么写,我也母鸡
之后会出现如下显示:
*** 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
继续测试输入:
In[5]:text1
会输出:
Out[5]:
<Text: Moby Dick by Herman Melville 1851>
再测试输入:
In[6]: text1.concordance("monstrous")
输出:
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ...
ok,这里就演示那么多,到此,NLP的环境就装好了,调试完毕,可以用于自己的实验了。
3 参考网址
http://www.jianshu.com/p/9c48e8edc7aa
http://blog.csdn.net/huyoo/article/details/12188573
http://blog.csdn.net/u010784534/article/details/48847697
http://blog.csdn.net/sinat_28224453/article/details/51462935