欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

NLTK 3.2.4 环境搭建教程

时间:2021-09-20 09:09:08|栏目: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 ?Cm pip install nltk

安装成功。

在IDLE中输入命令

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

终于出现如下NLTK Downloader界面

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

>>>from nltk.book import *

上一篇:Python基本数据类型详细介绍

栏    目:Python代码

下一篇:python常见的格式化输出小结

本文标题:NLTK 3.2.4 环境搭建教程

本文地址:http://www.codeinn.net/misctech/176250.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有