NLTK3.2.4環境搭建
阿新 • • 發佈:2019-02-02
系統環境: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 *