Using Pyinstaller with NLTK results in error: can't find nltk_data

后端 未结 1 1278
广开言路
广开言路 2021-01-14 15:17

I am attempting to export a simple GUI that used NLTK as an exe with Python 3.6 and Windows 10.

When I run PyInstaller to freeze my simple program as an exe I get th

1条回答
  •  囚心锁ツ
    2021-01-14 15:35

    It seems that it is a known bug for the hook of PyInstaller for nltk. An easy way to fix it is to edit this file:

    /Lib/site-packages/PyInstaller/hooks/hook-nltk.py
    

    And comment the lines iterate over nltk_data:

    #-----------------------------------------------------------------------------
    # Copyright (c) 2005-2018, PyInstaller Development Team.
    #
    # Distributed under the terms of the GNU General Public License with exception
    # for distributing bootloader.
    #
    # The full license is in the file COPYING.txt, distributed with this software.
    #-----------------------------------------------------------------------------
    
    
    # hook for nltk
    import nltk
    from PyInstaller.utils.hooks import collect_data_files
    
    # add datas for nltk
    datas = collect_data_files('nltk', False)
    
    # loop through the data directories and add them
    # for p in nltk.data.path:
    #     datas.append((p, "nltk_data"))
    
    datas.append(("", "nltk_data"))
    
    # nltk.chunk.named_entity should be included
    hiddenimports = ["nltk.chunk.named_entity"]
    

    Remember to replace path_to_nltk_data with your currrent path for nltk_data.

    0 讨论(0)
提交回复
热议问题