NLTK3.2.4环境搭建

本文介绍了在Windows环境下安装和配置NLTK的过程,包括解决Python版本注册问题的方法,并提供了使用Python 3.6.1安装NLTK的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统环境:win7 32位

python:2.7.13,后改为3.6.1


安装NLTK

从网站下载:http://www.nltk.org/,完成后双击安装,但提示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 *





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值