0

我正在关注nltk 书第 1 章。我能够安装nltk( import nltk) 但无法通过运行下载图书语料库nltk.download()。它给了我getattrinfo failed错误。所以我开始快速浏览本章中的命令而不执行这些命令,因为给出的大多数示例都需要书籍语料库。

但现在我想尝试FreqDist示例

跑的时候FreqDist,我意识到我还没有做from nltk.book import *。所以,我再次尝试安装书籍语料库。现在,我完全厌倦了尝试各种帖子中给出的不同解决方案来修复getattrinfo failed导入 nltk 数据时发生的错误。(我尝试设置公司代理更改 nltk 下载器源链接等许多东西)

因此,我没有遵循使用 nltk 下载器的路线,而是尝试做一些可能很奇怪的事情。我从 下载ziphttps://github.com/nltk/ ,解压缩然后setup.py在其中运行。

现在当我运行时from nltk.book import *,我得到以下输出:

>>> 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 "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\corpus\util.py", line 63, in __load
    try: root = nltk.data.find('corpora/%s' % zip_name)
  File "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\data.py", line 641, in find
    raise LookupError(resource_not_found)
LookupError:
**********************************************************************
  Resource 'corpora/gutenberg.zip/gutenberg/' not found.  Please
  use the NLTK Downloader to obtain the resource:  >>>
  nltk.download()
  Searched in:
    - 'C:\\Users\\593932/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'D:\\path\\Softwares\\python\\WinPython-64bit-3.4.4.4Qt5\\python-3.4.4.amd64\\nltk_data'
    - 'D:\\path\\Softwares\\python\\WinPython-64bit-3.4.4.4Qt5\\python-3.4.4.amd64\\lib\\nltk_data'
    - 'C:\\Users\\593932\\AppData\\Roaming\\nltk_data'
**********************************************************************

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\book.py", line 20, in <module>
    text1 = Text(gutenberg.words('melville-moby_dick.txt'))
  File "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\corpus\util.py", line 99, in __getattr__
    self.__load()
  File "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\corpus\util.py", line 64, in __load
    except LookupError: raise e
  File "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\corpus\util.py", line 61, in __load
    root = nltk.data.find('corpora/%s' % self.__name)
  File "D:\path\Softwares\python\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\nltk\data.py", line 641, in find
    raise LookupError(resource_not_found)
LookupError:
**********************************************************************
  Resource 'corpora/gutenberg' not found.  Please use the NLTK
  Downloader to obtain the resource:  >>> nltk.download()
  Searched in:
    - 'C:\\Users\\593932/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'D:\\path\\Softwares\\python\\WinPython-64bit-3.4.4.4Qt5\\python-3.4.4.amd64\\nltk_data'
    - 'D:\\path\\Softwares\\python\\WinPython-64bit-3.4.4.4Qt5\\python-3.4.4.amd64\\lib\\nltk_data'
    - 'C:\\Users\\593932\\AppData\\Roaming\\nltk_data'
**********************************************************************
>>>

我手动复制粘贴的nltk文件夹也包含book.py在上面列出的各种文件夹中:

- 'C:\\Users\\593932/nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'D:\\path\\Softwares\\python\\WinPython-64bit-3.4.4.4Qt5\\python-3.4.4.amd64\\nltk_data'
- 'D:\\path\\Softwares\\python\\WinPython-64bit-3.4.4.4Qt5\\python-3.4.4.amd64\\lib\\nltk_data'
- 'C:\\Users\\593932\\AppData\\Roaming\\nltk_data'

但是没有用。如何从 github 下载的 zip 将这本书导入到我的解释器环境中,而不需要使用 nltk 下载器?甚至可能吗?

4

0 回答 0