NLTK debug记录——"[nltk_data] Error loading xxx"下载数据集失败

问题:运行nltk.download("xxx")时遇到连接下载失败Error

解决:

  1. 在gitee上下载对应的.zip词库包(如,nltk_data/pakages/copora/目录下的下载链接);
  2. NLTK下载数据集时会自动搜索某些以./nltk_data/为结尾的目录(见附注),找到一个这样的目录并确保自己有写这个目录的权限,如果上一层目录下没有nltk_data文件夹就新建一个名为nltk_data的文件夹,将1. 中下载的.zip文件上传到./nltk_data/下,重新运行代码即可。


【附注】找到nltk下载数据集时会搜索和存放的目录:

查看nltk的安装目录下的downloader.py下载代码,

vim ~/.local/lib/python3.8/site-packages/nltk/downloader.py

发现下载数据集的函数的注释中有以下备选目录:

``/usr/share/nltk_data``, ``/usr/local/share/nltk_data``,
``/usr/lib/nltk_data``, ``/usr/local/lib/nltk_data``, ``~/nltk_data``
复制代码
... ...
    def default_download_dir(self):
        """
        Return the directory to which packages will be downloaded by
        default.  This value can be overridden using the constructor,
        or on a case-by-case basis using the ``download_dir`` argument when
        calling ``download()``.

        On Windows, the default download directory is
        ``PYTHONHOME/lib/nltk``, where *PYTHONHOME* is the
        directory containing Python, e.g. ``C:\\Python25``.

        On all other platforms, the default directory is the first of
        the following which exists or which can be created with write
        permission: ``/usr/share/nltk_data``, ``/usr/local/share/nltk_data``,
        ``/usr/lib/nltk_data``, ``/usr/local/lib/nltk_data``, ``~/nltk_data``.
        """
... ...
复制代码

选择有写权限的目录创建并存放数据集的.zip压缩文件即可。 

posted on   Mju_halcyon  阅读(230)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示