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实现决策树并且使用Graphviz可视化的例子

Python实现决策树并且使用Graphviz可视化的例子

一、什么是决策树(decision tree)——机器学习中的一个重要的分类算法 决策树是一个类似于数据流程图的树结构:其中,每个内部节点表示一个属性上的测试,每个分支代表一个属性输出,...

python获取各操作系统硬件信息的方法

本文实例讲述了python获取各操作系统硬件信息的方法。分享给大家供大家参考。具体如下: 1. windows 使用WMI: (WMI官网地址:http://pypi.python.or...

Python读取properties配置文件操作示例

本文实例讲述了Python读取properties配置文件操作。分享给大家供大家参考,具体如下: 工作需要将Java项目的逻辑改为python执行,Java的很多配置文件都是.prope...

python遍历一个目录,输出所有的文件名的实例

python 获取一个文件夹内(包括子文件夹)所有文件的名字和路径 import os dir = "e:\\" for root, dirs, files in os.walk(d...

在CentOS6上安装Python2.7的解决方法

在CentOS6上yum安装工具是基于Python2.6.6的,所以在CentOS6上默认安装的是Python2.6.6,因为要在服务器系统为CentOS6上部署生产环境,但是代码都是基...