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只搜索当前脚本所在的目录,加载(entry-point)入口脚本运行目录和sys.path中包含的路径例如包的安装地址。所以如果要在当前脚本引用其他文件,除...

解决uWSGI的编码问题详解

发现问题 最近工作中遇到一个问题,在把 Flask 写的应用通过 Supervisor+uWSGI 部署到正式服务器上时,出现了这样的错误: Unable to print the...

pyqt 多窗口之间的相互调用方法

* 在编程开发中,一个程序不可避免的需要多窗口操作来实现具体的功能。 实现此功能的基本步骤(以三个窗口为例,使用主窗口调用其它两个窗口) # 主窗口 from PyQt5 impor...

详解将Django部署到Centos7全攻略

详解将Django部署到Centos7全攻略

Django部署到Cenos7需要安装大量的依赖包, 有很多坑需要踩, 这里是踩坑后探索出的标准化步骤 实验环境: 腾讯云centos7 用centos7.5镜像创建容器(这步操作按自己...

Pytorch Tensor的索引与切片例子

1. Pytorch风格的索引 根据Tensor的shape,从前往后索引,依次在每个维度上做索引。 示例代码: import torch a = torch.rand(4, 3...