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 the error: Unable to find “c:usersusrnltk_data” when adding binary and data files.
When I even copied the nltk_data folder here and I get an error in a different nltk.data.path path “c:usersusrappdatalocalprogramspythonpython36nltk_data”
JavaScript
x
24
24
1
import tkinter as tk
2
from nltk.corpus import stopwords
3
sw = stopwords.words('english')
4
5
counter = 0
6
def counter_label(label):
7
counter = 0
8
def count():
9
global counter
10
counter += 1
11
label.config(text=sw[counter])
12
label.after(1000, count)
13
count()
14
15
16
root = tk.Tk()
17
root.title("Counting Seconds")
18
label = tk.Label(root, fg="dark green")
19
label.pack()
20
counter_label(label)
21
button = tk.Button(root, text='Stop', width=25, command=root.destroy)
22
button.pack()
23
root.mainloop()
24
for pyinstaller I run
JavaScript
1
2
1
pyinstaller --onefile -- windowed test_tkinter.py
2
Advertisement
Answer
It seems that it is a known bug to the hook of PyInstaller named nltk
. An easy way to fix it is to edit this file:
JavaScript
1
2
1
<PythonPath>/Lib/site-packages/PyInstaller/hooks/hook-nltk.py
2
And comment the lines iterating over nltk_data
:
JavaScript
1
26
26
1
#-----------------------------------------------------------------------------
2
# Copyright (c) 2005-2018, PyInstaller Development Team.
3
#
4
# Distributed under the terms of the GNU General Public License with exception
5
# for distributing bootloader.
6
#
7
# The full license is in the file COPYING.txt, distributed with this software.
8
#-----------------------------------------------------------------------------
9
10
11
# hook for nltk
12
import nltk
13
from PyInstaller.utils.hooks import collect_data_files
14
15
# add datas for nltk
16
datas = collect_data_files('nltk', False)
17
18
# loop through the data directories and add them
19
# for p in nltk.data.path:
20
# datas.append((p, "nltk_data"))
21
22
datas.append(("<path_to_nltk_data>", "nltk_data"))
23
24
# nltk.chunk.named_entity should be included
25
hiddenimports = ["nltk.chunk.named_entity"]
26
Remember to replace path_to_nltk_data
with your currrent path for nltk_data
.