1.可直接去官网nltk:https://pypi.python.org/pypi/nltk 下载安装包 直接进行安装配置
2.nltk 3.2.2要求版本是Python 2.7或者3.4+
在直接使用官网的安装包进行安装进行安装时可能会报错,比如 我就遇到了Python -32 was required,which was not found in registry。
可能原因:
1.Python版本不对
2.注册表信息有误,Python未加入注册表
为解决此情况,可以使用建立脚本文件建立注册信息。(代码附在文末) ,然后运行该脚本,添加成功后再运行安装。
ps:也可以使用pip来进行快捷安装。
Python3.0 以上都自带pip,为保证库处于最新状态,可以先对pip进行更新,然后再安装nltk。
更新pip:Python -m pip install -U pip
安装nltk: Python -m pip install nltk
成功安装之后便可直接安装数据。
#===========================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()