nltkdata路径设置linux,NLTK data路径设置
安裝nltk后用這個命令:from nltk.book import *
按照正常的,應(yīng)該出現(xiàn)以下:
>>> 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
>>>
但是我出現(xiàn)的是這個:
>>> 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.
Traceback (most recent call last):
File "", line 1, in
from nltk.book import *
File "C:\Python26-B\lib\site-packages\nltk\book.py", line 22, in
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 __load
except LookupError: raise e
LookupError:
**********************************************************************
Resource u*corpora/gutenberg* not found. Please use the NLTK
Downloader 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時我更改了路徑,而默認(rèn)的搜索路徑中沒有我的nltk_data路徑。
在 http://www.datatang.com/data/16932 中找了如下內(nèi)容:
If you did not install the data to one of the above central locations, you will need to set the?NLTK_DATA?environment variable to specify the location of the data.? (On a Windows machine, do?right click on "My Computer", select Properties > Advanced > Environment Variables > User Variables > New...)
所以在電腦屬性環(huán)境變量中增加 NLTK_DATA ,設(shè)置自己的路徑后,重新打開Python 問題即解決。
總結(jié)
以上是生活随笔為你收集整理的nltkdata路径设置linux,NLTK data路径设置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: u盘里隐藏的文件怎么显示 U盘隐藏文件的
- 下一篇: 神舟精盾t96e怎么连接网线 神舟精盾t