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 -*- 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()