由于最近需要做項目,需要進行分詞等,查了資料之后,發現python NLTK很強大,于是就想試試看。在網上找了很多安裝資料,都不太完整,下載的時候也總是會出現一點小意外,最后終于也安裝成功了,所以分享下經驗。
初學者,請高手指出不合理的地方。
我的工作站環境是Win10 64 + Python 2.7.12 64 bit。
按照NLTK上安裝主頁上的指引如下:
Source installation (for 32-bit or 64-bit Windows) 1.Install Python: http://www.python.org/download/releases/2.7.3/2.Install Numpy (optional): http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy3.Install Setuptools: http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-py2.7.exe4.Install Pip: Start>Run... c:/Python27/Scripts/easy_install pip5.Install PyYAML and NLTK: Start>Run... c:/Python27/Scripts/pip install pyyaml nltk6.Test installation: Start>All Programs>Python27>IDLE, then type import nltk
前3步的安裝都比較簡單,如果為了更好的編輯,也可以安裝一下編輯軟件,如PyCharm,Sublime text2/3等等。在安裝的時候要注意安裝路徑,最好不要出現中文。
我在安裝第4步的時候出現了一點小問題,執行命令后報錯:Python version 2.7 required, which was not found in the registry,于是我又到網上查了資料,解決方法是:
1)自己新建一個register.py文件,在文件中復制黏貼以下內容,然后保存到自己的路徑,我是直接放到pyhon的安裝文件夾中;
# # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html 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!" if __name__ == "__main__": RegisterPy()
新聞熱點
疑難解答