Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nltk-hook unable to find nltk_data

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

like image 880
tam Avatar asked Feb 12 '19 22:02

tam


2 Answers

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

like image 149
ashu Avatar answered Oct 08 '22 18:10

ashu


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.

like image 20
András Pataki Avatar answered Oct 08 '22 18:10

András Pataki