Windows7 平臺下Python+NLTK環境搭建

1     安裝

開發環境:windows 7 64位 + 32 Python 2.7.12位python

 

聲明一下:因爲NLTK的官方網頁給出的安裝步驟中提到「Install Python 3.4:  http://www.python.org/ downloads   (avoid the 64-bit versions)」,即告訴你們別下載64位的python,所以我使用的是32位3.3.2版本。windows

 

1 安裝python,安裝路徑爲D:\mysoftware\Python27,並配置環境變量python2.7

  在path後面加上: ;D:\mysoftware\Python27測試

 

2 安裝Numpy,下載對應python 3.3版本的,我下載的是numpy-1.9.2-win32-superpack-python2.7.exespa

 

3 安裝pip.net

pip用來安裝後續的包,安裝pip前需確認已安裝Python和easy_install。調試

若是成功裝了python,則easy_install在Python安裝目錄下的scripts文件夾下,如,D:\mysoftware\Python27\Scripts。orm

進入Python安裝目錄下的Scripts路徑,執行blog

easy_install.exe pipip

出現下圖,說明pip安裝成功。

查看pip版本,輸入pip --version,回車出現:

pip 8.1.1 from d:\mysoftware\python27\lib\site-packages (python 2.7)

把pip路徑 加入環境變量path後面,這樣能夠直接從cmd 找到。

4 安裝nltk

利用pip安裝:

pip install nltk

5 安裝PyYAML

pip install PyYAML

 

 

7這些都安裝好,而後運行Python的IDE環境:

 

而後,Python Launcher會彈出下面這個界面,建議你選擇安裝全部的Packages,以避免去往後一而再、再而三的進行安裝,也爲你的後續開發提供一個穩定的環境。某些包的Status顯示「out of date」,你能夠沒必要理會,它基本不影響你的使用與開發。

 

修改下載目錄,點擊download下載,下載速度很慢,有時候還會報錯。

最好的方法是用使用@V_can打包好的的包網盤下載

下載地址1:https://pan.baidu.com/s/1slP4wfr

雲盤密:znx7

下載地址2:https://pan.baidu.com/share/init?shareid=100987267&uk=2720665201

雲盤密碼:4cp3

有兩種方法加入這些數據。

方法1:nltk_data.zip 解壓到python根目錄下:

方法2:本身放一個路徑,配置環境變量NLTK_DATA

 

 

2      NLTK測試

測試環境是否安裝好請按照下列步驟(所有在python console中完成,就是輸入一行輸出一行的那種IDE):
In[4]:from nltk.book import *
# 只輸入import nltk 會出錯的,但卻有不少博客上都這麼寫,我也母雞
以後會出現以下顯示:
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
繼續測試輸入:
In[5]:text1
會輸出:
Out[5]:
<Text: Moby Dick by Herman Melville 1851>
再測試輸入:
In[6]: text1.concordance("monstrous")
輸出:
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ...
ok,這裏就演示那麼多,到此,NLP的環境就裝好了,調試完畢,能夠用於本身的實驗了。

 

3  參考網址

http://www.jianshu.com/p/9c48e8edc7aa

http://blog.csdn.net/huyoo/article/details/12188573

http://blog.csdn.net/u010784534/article/details/48847697

http://blog.csdn.net/sinat_28224453/article/details/51462935

相關文章
相關標籤/搜索