Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python LookupError:从nltk.book导入*_Python_Import_Ipython_Nltk_Anaconda - Fatal编程技术网

Python LookupError:从nltk.book导入*

Python LookupError:从nltk.book导入*,python,import,ipython,nltk,anaconda,Python,Import,Ipython,Nltk,Anaconda,在iPython控制台中,我从nltk.book import输入了,得到了几个lookuperror。下面显示了我得到的代码 *** 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

在iPython控制台中,我从nltk.book import输入了
,得到了几个lookuperror。下面显示了我得到的代码

*** 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.
---------------------------------------------------------------------------
LookupError Traceback (most recent call last)
<ipython-input-3-8446809acbd4> in <module>()
 ----> 1 from nltk.book import*

C:\Users\dell\Anaconda\lib\site-packages\nltk-3.0.3-py2.7.egg\nltk\book.py in <module>()
 20 print("Type: 'texts()' or 'sents()' to list the materials.")
 21 
---> 22 text1 = Text(gutenberg.words('melville-moby_dick.txt'))
 23 print("text1:", text1.name)
 24 

 C:\Users\dell\Anaconda\lib\site-packages\nltk-3.0.3-py2.7.egg\nltk\corpus\util.pyc in __getattr__(self, attr)
 97             raise AttributeError("LazyCorpusLoader object has no attribute '__bases__'")
 98 
 ---> 99         self.__load()
100         # This looks circular, but its not, since __load() changes our
101         # __class__ to something new:

 C:\Users\dell\Anaconda\lib\site-packages\nltk-3.0.3-py2.7.egg\nltk\corpus\util.pyc in __load(self)
 62             except LookupError as e:
 63                 try: root = nltk.data.find('corpora/%s' % zip_name)
 ---> 64                 except LookupError: raise e
 65 
 66         # Load the corpus.

 LookupError: 
 **********************************************************************
 Resource u'corpora/gutenberg' not found.  Please use the NLTK
 Downloader to obtain the resource:  >>> nltk.download()
 Searched in:
- 'C:\\Users\\dell/nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'C:\\Users\\dell\\Anaconda\\nltk_data'
- 'C:\\Users\\dell\\Anaconda\\lib\\nltk_data'
- 'C:\\Users\\dell\\AppData\\Roaming\\nltk_data'
**********************************************************************

In [4]: 
***NLTK手册的介绍性示例***
正在加载text1,…,text9和sent1,…,sent9
键入要查看的文本或句子的名称。
键入:“text()”或“sents()”以列出材料。
---------------------------------------------------------------------------
LookupError回溯(上次最近的调用)
在()
---->1从nltk.book导入*
C:\Users\dell\Anaconda\lib\site packages\nltk-3.0.3-py2.7.egg\nltk\book.py in()
20打印(“键入:‘text()’或‘sents()’以列出材料。”)
21
--->22 text1=Text(gutenberg.words('melville-moby_dick.txt'))
23打印(“text1:,text1.名称)
24
C:\Users\dell\Anaconda\lib\site packages\nltk-3.0.3-py2.7.egg\nltk\corpus\util.pyc in uuuu getattr\uuuu(self,attr)
97 raise AttributeError(“LazyCorpusLoader对象没有属性'\uuuu bases')
98
--->99自加载()
100#这看起来是圆形的,但它不是,因为u load()改变了我们的
101#uuuu类uuuuuuu新事物:
C:\Users\dell\Anaconda\lib\site packages\nltk-3.0.3-py2.7.egg\nltk\corpus\util.pyc in\uuu load(self)
62除外观错误为e外:
63 try:root=nltk.data.find('corpora/%s'%zip\u name)
--->64除LookupError外:升高e
65
66#加载语料库。
LookupError:
**********************************************************************
未找到“语料库/古腾堡”资源。请使用NLTK
下载程序以获取资源:>>>>nltk.download()
搜索:
-'C:\\Users\\dell/nltk\u数据'
-'C:\\nltk\U数据'
-'D:\\nltk\U数据'
-'E:\\nltk\U数据'
-'C:\\Users\\dell\\Anaconda\\nltk\u数据'
-'C:\\Users\\dell\\Anaconda\\lib\\nltk\u数据'
-'C:\\Users\\dell\\AppData\\Roaming\\nltk\U数据'
**********************************************************************
在[4]中:

我能知道为什么会出现这些错误吗?

你在
nltk.book
中丢失了
Gutenberg
语料库,因此出现了错误。 错误是自描述性的

您需要使用
nltk.download()
下载语料库。

下载语料库后,重新运行命令并检查是否再次出现错误。如果是的话,那就是另一个语料库。也下载那个语料库

从nltk.book导入*
不是首选方法,建议只导入将在代码中使用的语料库。 您可以使用nltk.corpus import gutenberg中的


如NLTK书籍所述,准备使用该书的方法是打开
NLTK.download()
弹出窗口,转到“收藏”选项卡,然后下载“书籍”收藏。这样做,你就可以毫无意外地阅读本书的其余部分


顺便说一句,您可以在python控制台中执行
nltk.download(“book”)

在没有弹出窗口的情况下执行同样的操作,也许您应该在以下目录中下载nltk_数据包:


它似乎只在特定位置搜索数据(如错误描述中所述)尝试将nltk的内容复制到其中一个目录中(或创建一个目录),如D:\nltk\U data 这为我解决了问题(因为即使Guttenber已经下载,错误也会继续出现,因为它在那个地方没有找到)

您得到的错误摘录:(这些是目录,您可以在其中选择nltk内容的放置位置,以便找到它)

  • 'C:\Users\dell/nltk\u数据'
  • “C:\nltk\U数据”
  • 'D:\nltk\U数据'
  • “E:\nltk\U数据”
  • 'C:\Users\dell\Anaconda\nltk\u data'
  • 'C:\Users\dell\Anaconda\lib\nltk\u data'
  • 'C:\Users\dell\AppData\Roaming\nltk\u data'

尝试使用
nltk.dowwnload()
这将打开一个面板。从那里,在
Corpora
下载
gutenberg
book/Corpora并再次尝试您的命令谢谢!成功了!下载了错误消息中提到的语料库。我需要其他的语料库吗?以后没有再下载了?谢谢!我只下载了每次出现在错误中的语料库。我还需要其他语料库吗?这取决于您的应用程序及其使用情况。当你阅读nltk这本书时,你会意识到你不需要大部分语料库。所需的一些语料库包括
brown、treebank、wordnet、words、conll2000、conll2002、ieer、gutenberg