1.直接在cmd端输入
>>>pip install nltk
>>>nltk.download()
2.在查阅了csdn各种博客后,我到(https://github.com/nltk/nltk_data),官网上点击Clone or download—>Download ZIP下载了nltk的数据包
解压后,实际有用的是那个packages文件夹
因为看到nltk的Search路径如下图,所以我在E:\anacoda33\里面创建了一个nltk_data文件夹,用来放上面的packages文件夹。(你也可以以选任意一条路径,创建nltk_data这个文件夹,比如在C、D、E盘里任选一个创建,应该不会错)
我是将packages文件夹里面的东西,全部文件复制下来,然后黏贴在nltk_data文件夹里,nltk_data文件夹里涉及到的所有压缩文件都要解压到当前文件夹。最后差不多是这样一个界面
然后我在python里输入from nltk.book import *,进行检查,他告诉我 【Resource ?[93mnps_chat?[0m not found.
Please use the NLTK Downloader to obtain the resource:】然后还给出解决方法【 ?[31m>>> import nltk>>>nltk.download(‘nps_chat’)】
所以我在python终端输入:【>>>import nltk >>>nltk.download(‘nps_chat’)】最后得出【[nltk_data] Downloading package nps_chat to E:\anacoda33\nltk_data…
[nltk_data] Unzipping corpora\nps_chat.zip.
True】看到True我就放心了。
**>>> from nltk.book import
*** 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
Traceback (most recent call last):
File “E:\anacoda33\lib\site-packages\nltk\corpus\util.py”, line 86, in __load
root = nltk.data.find(’{}/{}’.format(self.subdir, zip_name))
File “E:\anacoda33\lib\site-packages\nltk\data.py”, line 699, in find
raise LookupError(resource_not_found)
LookupError:
Resource ?[93mnps_chat?[0m not found.
Please use the NLTK Downloader to obtain the resource:
?[31m>>> import nltk
nltk.download(‘nps_chat’)
?[0m
Attempted to load ?[93mcorpora/nps_chat.zip/nps_chat/?[0m
Searched in:
- 'C:\\Users\\Administrator/nltk_data'
- 'E:\\anacoda33\\nltk_data'
- 'E:\\anacoda33\\share\\nltk_data'
- 'E:\\anacoda33\\lib\\nltk_data'
- 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 1, in
File “E:\anacoda33\lib\site-packages\nltk\book.py”, line 40, in
text5 = Text(nps_chat.words(), name=“Chat Corpus”)
File “E:\anacoda33\lib\site-packages\nltk\corpus\util.py”, line 123, in getattr
self.__load()
File “E:\anacoda33\lib\site-packages\nltk\corpus\util.py”, line 88, in __load
raise e
File “E:\anacoda33\lib\site-packages\nltk\corpus\util.py”, line 83, in __load
root = nltk.data.find(’{}/{}’.format(self.subdir, self.__name))
File “E:\anacoda33\lib\site-packages\nltk\data.py”, line 699, in find
raise LookupError(resource_not_found)
LookupError:
Resource ?[93mnps_chat?[0m not found.
Please use the NLTK Downloader to obtain the resource:
?[31m>>> import nltk
nltk.download(‘nps_chat’)
?[0m
Attempted to load ?[93mcorpora/nps_chat?[0m
Searched in:
- 'C:\\Users\\Administrator/nltk_data'
- 'E:\\anacoda33\\nltk_data'
- 'E:\\anacoda33\\share\\nltk_data'
- 'E:\\anacoda33\\lib\\nltk_data'
- 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
**>>> import nltk
nltk.download(‘nps_chat’)**
[nltk_data] Downloading package nps_chat to E:\anacoda33\nltk_data…
[nltk_data] Unzipping corpora\nps_chat.zip.
True
接着我又输入from nltk.book import*来检查nltk是否安装成功,只要它显示找不到什么东西,我就用import nltk
和nltk.download('你要找的东西’)进行下载,返回True就可以了
最后一次输入,就没有出现Error和Traceback (most recent call last)这些讨厌的字眼了
from nltk.book import *
*** 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
然后我看博客上有人写,有了上面这些后,再输一些代码进行检测,所以我又输入了下面两个代码【>>>text1】【>>>text1.concordance(“monstrous”)】,nltk是否安装成功。我就照着他的输,然后结果与他一致就行。现在可以随便使用nltk进行词频统计了
text1
text1.concordance(“monstrous”)
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . … This came towards us ,
ON OF THE PSALMS . " Touching that monstrous bulk of the whale or ork we have r
ll over with a heathenish array of monstrous clubs and spears . Some were thick
d as you gazed , and wondered what monstrous cannibal and savage could ever hav
that has survived the flood ; most monstrous and most mountainous ! That Himmal
they might scout at Moby Dick as a monstrous fable , or still worse and more de
th of Radney .’" CHAPTER 55 Of the Monstrous Pictures of Whales . I shall ere l
ing Scenes . In connexion with the monstrous pictures of whales , I am strongly
ere to enter upon those still more monstrous stories of them which are to be fo
ght have been rummaged out of this monstrous cabinet there is no telling . But
of Whale - Bones ; for Whales of a monstrous size are oftentimes cast up dead u