本文記錄了NLTK 3.2.4 環境搭建的方法,供大家參考,具體內容如下
系統環境:win7 32位
python:2.7.13,后改為3.6.1
安裝NLTK
從網站下載,完成后雙擊安裝,但提示Python version -32 required, which was not found in the registry.
從網上搜索到以下解決方案:
新建文件D:/register.py,通過腳本建立注冊信息
#===============register.py====================###!/usr/bin/env python# -*- coding:utf-8 -*-import sysfrom _winreg import * # tweak as necessaryversion = 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 *
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。
新聞熱點
疑難解答