NLTK 3.2.2 安装经验
Nltk 3.2.2要求Python版本是Python2.7 或者Python3.4+。
Nltk 3.2.3 如果是从网站上直接下载程序进行安装可能会报错:Python version -32 required, which was not found in the registry,
原因可能有以下几方面:
1) Python版本不对:重新安装合适的Python版本
2) Python注册信息未加入到注册表中
3) Python注册信息不对
针对后面两种情况,我们可以直接通过脚本register.py(具体代码内容见本文后面)建立注册信息,然后运行该脚本。注册信息添加成功后重新安装nltk模块即可。
Python3.0 以上版本都自带有pip,可以通过pip快捷安装nltk的最新版本,但为了保证库的版本最新,可以先更新pip
1) 更新pip:py –m pip install –upgrade pip
2) 安装nltk: py –m pip install nltk
当出现打印消息:successfully installed nltk-3.2.2 six-1.10.0时表示安装成功。
#===========================register.py=======================================##
#!/usr/bin/env python#-*- coding:utf-8 -*-
importsysfrom 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
)defRegisterPy():try:
reg=OpenKey(HKEY_CURRENT_USER, regpath)exceptEnvironmentError 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 andQueryValue(reg, pythonkey)==pythonpath):
CloseKey(reg)print ("=== Python", version, "is already registered!")returnCloseKey(reg)print ("*** Unable to register!")print ("*** You probably have another Python installation!")
RegisterPy()
解决Python3 NLTK 3.2.2 安装问题
这篇博客分享了在安装NLTK 3.2.2时遇到的问题及解决方案,包括Python版本不匹配、注册表信息问题等。提供了一个名为register.py的脚本用于创建注册信息,并指导如何使用pip更新和安装nltk模块。
987

被折叠的 条评论
为什么被折叠?



