ananconda下运行nltk报错解决办法

报错内容:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)
  File "E:\anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "E:/anaconda_workspace/myfirst_NLP.py", line 14, in <module>
    for text in gutenberg.fileids():
  File "E:\anaconda2\lib\site-packages\nltk\corpus\util.py", line 116, in __getattr__
    self.__load()
  File "E:\anaconda2\lib\site-packages\nltk\corpus\util.py", line 81, 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.book但是没有东西,所以你需要把下载路径设置成这些当中的任何一个,比如C:\nltk_data,或者你把下载好的包直接复制到那个文件夹下,再导入就好了。


在终端输入:

>>> import nltk  
>>> nltk.download()  

运行出现:

showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
图片:



点击all,然后download下载就可以啦。



猜你喜欢

转载自blog.csdn.net/anneqiqi/article/details/77774305