NLTK 3.2.4 环境搭建教程

yipeiwu_com5年前Python基础

本文记录了NLTK 3.2.4 环境搭建的方法,供大家参考,具体内容如下

系统环境:win7 32位

python:2.7.13,后改为3.6.1

安装NLTK

从网站下载,完成后双击安装,但提示Python version -32 required, which was not found in the registry.

从网上搜索到以下解决方案:

新建文件D:\register.py,通过脚本建立注册信息

#===============register.py====================##
#!/usr/bin/env python
# -*- coding:utf-8 -*-
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!")
 
RegisterPy()

打开cmd,执行

运行安装文件,仍然失败= =(有大神能解决的请私信或留言 谢谢!)

于是放弃了中文版的NLP with Python,重投http://www.nltk.org/book/。

安装最新版python3.6.1,cmd中直接执行

py –m pip install nltk

安装成功。

在IDLE中输入命令

>>>import nltk
>>>nltk.download()

终于出现如下NLTK Downloader界面

下载完毕后,就可以在IDLE中加载NLTK并使用了。

>>>from nltk.book import *

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

相关文章

Python中修改字符串的四种方法

在Python中,字符串是不可变类型,即无法直接修改字符串的某一位字符。  因此改变一个字符串的元素需要新建一个新的字符串。 常见的修改方法有以下4种。 方法1:将字符串转...

python实现数据写入excel表格

本文实例为大家分享了python数据写入excel表格的具体代码,供大家参考,具体内容如下 安装: xlsxwriter第三方库 code: #!/usr/bin/env/pytho...

python 基于dlib库的人脸检测的实现

python 基于dlib库的人脸检测的实现

本周暂时比较清闲,可以保持每日一更的速度。 国外身份证项目新增需求,检测出身份证正面的人脸。最开始考虑mobilenet-ssd,经同事提醒,有现成的人脸库dlib,那就用传统方法尝试一...

Jupyter中直接显示Matplotlib的图形方法

Jupyter中直接显示Matplotlib的图形方法

一.使用以下cmd命令生成ipython_config.py 文件 ipython profile create 二.在ipython_config.py中添加以下代码 c....

Python实现的一个找零钱的小程序代码分享

Python写的一个按面值找零钱的程序,按照我们正常的思维逻辑从大面值到小面值的找零方法,人民币面值有100元,50元,20元,10元,5元,1元,5角,1角,而程序也相应的设置了这些面...