暗小汐的专栏

安装nltk后用这个命令:from nltk.book import *按照正常的,应该出现以下:>>> from nltk.book import **** Introductory Examples for the NLTK Book ***Loading text1, …, text9 and sent1, …, sent9Type the name of the text or sentence to view it.Type: *texts()* or *sents()* to list the materials.text1: Moby Dick by Herman Melville 1851text2: Sense and Sensibility by Jane Austen 1811text3: The Book of Genesistext4: Inaugural Address Corpustext5: Chat Corpustext6: Monty Python and the Holy Grailtext7: Wall Street Journaltext8: Personals Corpustext9: The Man Who Was Thursday by G . K . Chesterton 1908>>>但是我出现的是这个:>>> from nltk.book import **** Introductory Examples for the NLTK Book ***Loading text1, …, text9 and sent1, …, sent9Type the name of the text or sentence to view it.Type: *texts()* or *sents()* to list the materials.Traceback (most recent call last):File "<pyshell#0>", line 1, in <module>from nltk.book import *File "C:\Python26-B\lib\site-packages\nltk\book.py", line 22, in <module>text1 = Text(gutenberg.words(*melville-moby_dick.txt*))File "C:\Python26-B\lib\site-packages\nltk\corpus\util.py", line 99, in __getattr__self.__load()File "C:\Python26-B\lib\site-packages\nltk\corpus\util.py", line 64, in __loadexcept LookupError: raise eLookupError: **********************************************************************Resource u*corpora/gutenberg* not found. Please use the NLTKDownloader to obtain the resource: >>> nltk.download()Searched in:- *C:\\Users\\XXXXXX/nltk_data*- *C:\\nltk_data*- *D:\\nltk_data*- *E:\\nltk_data*- *C:\\Python26-B\\nltk_data*- *C:\\Python26-B\\lib\\nltk_data*- *C:\\Users\\XXXXX\\AppData\\Roaming\\nltk_data***********************************************************************

>>>

看下面的目录就明白了,,下载nltk_data时我更改了路径,而默认的搜索路径中没有我的nltk_data路径。

在 中找了如下内容:

If you did not install the data to one of the above central locations, you will need to set theNLTK_DATAenvironment variable to specify the location of the data. (On a Windows machine, doright click on "My Computer", select Properties > Advanced > Environment Variables > User Variables > New…)

所以在电脑属性环境变量中增加 NLTK_DATA ,设置自己的路径后,重新打开Python 问题即解决。

在开始时却总是不厌其烦地渗透入生活的缝隙,

暗小汐的专栏

相关文章:

你感兴趣的文章:

标签云: