nltk-hook unable to find nltk_data

不羁岁月 提交于 2019-12-24 00:24:36

问题


When using pyinstaller to build an executable I get

unable to find /home/usr/nltk_data

when adding binary and data files.

I've tried almost every single solution on the internet


回答1:


Change hook-nltk.py file to this

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"]

and change remove the double space to single space of file "pyi_rth_nltk.py" instead of "pyi_rth__nltk.py".This file can be at \Anaconda3\Lib\site-packages\PyInstaller\loader\rthooks




回答2:


I solved the problems editing the pyinstaller nltk-hook (inside python3). After much research, I decided to go it alone in the code structure. I solved my problem by commenting on the lines: datas=[]

'''for p in nltk.data.path: datas.append((p, "nltk_data"))'''

hiddenimports = ["nltk.chunk.named_entity"]

What's more, you need to rename the file: pyi_rth__nltk.cpython-36.pyc to pyi_rth_nltk.cpython-36.pyc This file have 1 more underline. Warning with the python version.



来源:https://stackoverflow.com/questions/54659466/nltk-hook-unable-to-find-nltk-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!