win10 64bit下python NLTK安装教程

yipeiwu_com5年前Python基础

由于最近需要做项目,需要进行分词等,查了资料之后,发现python NLTK很强大,于是就想试试看。在网上找了很多安装资料,都不太完整,下载的时候也总是会出现一点小意外,最后终于也安装成功了,所以分享下经验。

初学者,请高手指出不合理的地方。

我的工作站环境是Win10 64 + Python 2.7.12 64 bit。

按照NLTK上安装主页上的指引如下:

Source installation (for 32-bit or 64-bit Windows)
 
1.Install Python: http://www.python.org/download/releases/2.7.3/
2.Install Numpy (optional): http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
3.Install Setuptools: http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-py2.7.exe
4.Install Pip: Start>Run... c:\Python27\Scripts\easy_install pip
5.Install PyYAML and NLTK: Start>Run... c:\Python27\Scripts\pip install pyyaml nltk
6.Test installation: Start>All Programs>Python27>IDLE, then type import nltk

前3步的安装都比较简单,如果为了更好的编辑,也可以安装一下编辑软件,如PyCharm,Sublime text2/3等等。在安装的时候要注意安装路径,最好不要出现中文。

我在安装第4步的时候出现了一点小问题,执行命令后报错:Python version 2.7 required, which was not found in the registry,于是我又到网上查了资料,解决方法是:

1)自己新建一个register.py文件,在文件中复制黏贴以下内容,然后保存到自己的路径,我是直接放到pyhon的安装文件夹中;

# 
# script to register Python 2.0 or later for use with win32all 
# and other extensions that require Python registry settings 
# 
# written by Joakim Loew for Secret Labs AB / PythonWare 
# 
# source: 
# http://www.pythonware.com/products/works/articles/regpy20.htm 
# 
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html 
  
import sys 
  
from _winreg import * 
  
# tweak as necessary 
version = sys.version[:3] 
installpath = sys.prefix 
  
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) 
installkey = "InstallPath" 
pythonkey = "PythonPath" 
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( 
  installpath, installpath, installpath 
) 
  
def RegisterPy(): 
  try: 
    reg = OpenKey(HKEY_CURRENT_USER, regpath) 
  except EnvironmentError as e: 
    try: 
      reg = CreateKey(HKEY_CURRENT_USER, regpath) 
      SetValue(reg, installkey, REG_SZ, installpath) 
      SetValue(reg, pythonkey, REG_SZ, pythonpath) 
      CloseKey(reg) 
    except: 
      print "*** Unable to register!" 
      return 
    print "--- Python", version, "is now registered!" 
    return 
  if (QueryValue(reg, installkey) == installpath and 
    QueryValue(reg, pythonkey) == pythonpath): 
    CloseKey(reg) 
    print "=== Python", version, "is already registered!" 
    return 
  CloseKey(reg) 
  print "*** Unable to register!" 
  print "*** You probably have another Python installation!" 
  
if __name__ == "__main__": 
  RegisterPy() 

2)Ctrl+R打开cmd,然后进入python的安装目录(如果有配置环境变量的话,就不用这么麻烦了,可以直接命令操作),输入:python register.py(这个是刚才存错register.py的路径,如D:\register.py)。出现Python 2.7 is already registered!则表示配置成功。

3)接着,进入Scripts目录,输入:easy_install pip,提示安装成功。

第5步是安装PyYAML和NLTK。直接在刚才的目录中输入:pip install pyyaml nltk,这时会提示安装是否成功,若安装成功可以接着下一步。

此时,就可以到IDLE中进行下载NLTK的数据包:

稍等一会,就出现了如下的页面,弹出如下窗口,即完成了。我是选择下载了所有的data,你可以根据自己的需要进行下载。要等很久才会完成这个过程,慢慢来,最后就可以测试啦。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python寻找两个有序数组的中位数实例详解

Python寻找两个有序数组的中位数实例详解

Python寻找两个有序数组的中位数 审题: 1.找出意味着这是一个查找算法题 2.算法复杂度log级别,就是提示你是二分查找 3.二分查找实现一般为递归  (1)递归包括递...

深入浅析Python中list的复制及深拷贝与浅拷贝

深入浅析Python中list的复制及深拷贝与浅拷贝

在Python中,经常要对一个list进行复制。对于复制,自然的就有深拷贝与浅拷贝问题。深拷贝与浅拷贝的区别在于,当从原本的list复制出新的list之后,修改其中的任意一个是否会对另一...

Python中的Function定义方法第1/2页

下面就先定义一个函数: 复制代码 代码如下:def foo(): print('function') foo() 在上述代码中,定义了一个名为foo的函数,这个函数没有参数。最后一行代码...

Python 正则表达式操作指南

原文作者:A.M. Kuchling (amk@amk.ca) 授权许可:创作共享协议 翻译人员:FireHare 校对人员:Leal 适用版本:Python 1.5 及后续版本http...

解决Python print 输出文本显示 gbk 编码错误问题

前阵子想爬点东西,结果一直提示错误UnicodeEncodeError: ‘gbk' codec can't encode character ‘\xa0' in position,在网...