nltk-hook无法找到nltk_data

tam*_*tam 2 python hook pyinstaller nltk

当使用pyinstaller生成可执行文件时,我得到

找不到/ home / usr / nltk_data

添加二进制文件和数据文件时。

我已经尝试了互联网上几乎所有的解决方案

ash*_*shu 6

将hook-nltk.py文件更改为此

import os
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:
    if os.path.exists(p):
        datas.append((p, "nltk_data"))

# nltk.chunk.named_entity should be included
hiddenimports = ["nltk.chunk.named_entity"]
Run Code Online (Sandbox Code Playgroud)

并更改以删除文件“ pyi_rth_nltk.py”而不是“ pyi_rth__nltk.py”的双倍空格。该文件可以位于\ Anaconda3 \ Lib \ site-packages \ PyInstaller \ loader \ rthooks

  • anaconda3\Lib\site-packages\PyInstaller\hooks (3认同)