由于最近需要做項目,需要進行分詞等,查了資料之后,發現python NLTK很強大,于是就想試試看。在網上找了很多安裝資料,都不太完整,下載的時候也總是會出現一點小意外,最后終于也安裝成功了,所以分享下經驗。
初學者,請高手指出不合理的地方。
我的工作站環境是Win10 64 + Python 2.7.12 64 bit。
按照NLTK上安裝主頁上的指引如下:
1
2
3
4
5
6
7
8
|
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 / #numpy 3.Install Setuptools: http: / / pypi.python.org / packages / 2.7 / s / setuptools / setuptools - 0.6c11 .win32 - py2. 7.exe 4.Install Pip: Start>Run... c:\Python27\Scripts\easy_install pip 5.Install PyYAML and NLTK: Start>Run... c:\Python27\Scripts\pip install pyyaml nltk 6.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的安裝文件夾中;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# # 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() |
2)Ctrl+R打開cmd,然后進入python的安裝目錄(如果有配置環境變量的話,就不用這么麻煩了,可以直接命令操作),輸入:python register.py(這個是剛才存錯register.py的路徑,如D:\register.py)。出現Python 2.7 is already registered!則表示配置成功。
3)接著,進入Scripts目錄,輸入:easy_install pip,提示安裝成功。
第5步是安裝PyYAML和NLTK。直接在剛才的目錄中輸入:pip install pyyaml nltk,這時會提示安裝是否成功,若安裝成功可以接著下一步。
此時,就可以到IDLE中進行下載NLTK的數據包:
稍等一會,就出現了如下的頁面,彈出如下窗口,即完成了。我是選擇下載了所有的data,你可以根據自己的需要進行下載。要等很久才會完成這個過程,慢慢來,最后就可以測試啦。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/u010297791/article/details/52402577