Search code examples
python-3.xpyinstaller

How to use pyInstaller to completely pack all the necessary Library?


I have already used pyinstaller to create a standalone aplication of my python aplication

pyinstaller --windowed app.py

and it actually run in my computer and work just as intended, but when I tried it on my friend's computer, it didn't work. It runs but somehow it can't process the text.

here are the library used:

import tkinter as Tk
import tkinter.ttk as ttk
import tkinter.scrolledtext as ScrollTxt
from tkinter import END,E,W,filedialog,messagebox
from nltk.tokenize import sent_tokenize, RegexpTokenizer, word_tokenize
import math
import fileinput
from textblob import TextBlob as tb
from nltk.tag import pos_tag, map_tag
from nltk.corpus import stopwords

if you want to see the result file: https://www.dropbox.com/s/mfdnaaoik7w0r23/TextSummaryV73.rar?dl=0

anybody knows what's wrong or what's missing?

I think it's either nltk or textblob, can anyone help how to add these files into the package?

EDIT: I have added nltk and textblob into the Python Application's directory using spec files. now the problem is, how to make the program know that these two imports are already inside the directory?


Solution

  • You can copy the nltk_data folder from where it is downloaded by nltk to your app directory. In your script where you require the library use Sandeep's suggestion with:

    basedir = os.path.abspath(os.path.dirname(__file__))
    import nltk
    nltk.data.path.append(basedir + 'nltk_data')
    

    Then build your pyinstaller file with

    pyinstaller -F --add-data "nltk_data;nltk_data" app.py