NLTK 3.2.4 环境搭建教程

yipeiwu_com6年前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面向对象之类和对象属性的增删改查操作。分享给大家供大家参考,具体如下: 一、类属性的操作 # -*- coding:utf-8 -*- #! python2...

python在非root权限下的安装方法

以前在使用Python的时候,都是使用root用户安装好的全局python,现在,因为root用户安装的Python版本太低,同时自己没有root权限去对全局Python升级,所以要在非...

OpenCV图像颜色反转算法详解

OpenCV图像颜色反转算法详解

前言 图像颜色的反转,比较简单的思路就是使用255减去当前值,从而得到反转后的图像.原始图片: 1.灰度图像的颜色反转 import cv2 import numpy as n...

Python算法中的时间复杂度问题

Python算法中的时间复杂度问题

在实现算法的时候,通常会从两方面考虑算法的复杂度,即时间复杂度和空间复杂度。顾名思义,时间复杂度用于度量算法的计算工作量,空间复杂度用于度量算法占用的内存空间。 本文将从时间复杂度的概...

Django代码性能优化与Pycharm Profile使用详解

Django代码性能优化与Pycharm Profile使用详解

前言 pycharm是python的一个商业的集成开发工具,本人感觉做python开发还是很好用的,django是一个很流行的python web开源框架,本文将通过实例代码给大家介绍了...