0

I'm trying to export my tkinter app as a standalone executable file using pyinstaller.

Im using autpy-to-exe GUI to run it. and the command is as follows

pyinstaller --noconfirm --onedir --windowed --debug "all"  "D:/Internship/keras-video-classification/exe/predictGUI.py"
Running auto-py-to-exe v2.7.8
Building directory: C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk
Provided command: pyinstaller --noconfirm --onedir --windowed --debug "all"  "D:/Internship/keras-video-classification/exe/predictGUI.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onedir --windowed --debug all D:/Internship/keras-video-classification/exe/predictGUI.py --distpath C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\application --workpath C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\build --specpath C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk

86827 INFO: PyInstaller: 4.0
86837 INFO: Python: 3.8.2
86845 INFO: Platform: Windows-10-10.0.18362-SP0
86856 INFO: wrote C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\predictGUI.spec
86874 INFO: UPX is not available.
86909 INFO: Extending PYTHONPATH with paths
['D:\\Internship\\keras-video-classification\\exe',
 'C:\\Users\\Slaye\\AppData\\Local\\Temp\\tmpf0x1a0dk']
86963 INFO: checking Analysis
86970 INFO: Building Analysis because Analysis-00.toc is non existent
86977 INFO: Initializing module dependency graph...
87001 INFO: Caching module graph hooks...
87065 INFO: Analyzing base_library.zip ...
95434 INFO: Processing pre-find module path hook distutils from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
95446 INFO: distutils: retargeting to non-venv dir 'c:\\python\\python38-32\\lib'
103510 INFO: Caching module dependency graph...
103884 INFO: running Analysis Analysis-00.toc
103938 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\python\python38-32\python.exe
104425 INFO: Analyzing D:\Internship\keras-video-classification\exe\predictGUI.py
112731 INFO: Processing pre-find module path hook site from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
112738 INFO: site: retargeting to fake-dir 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\fake-modules'
118214 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
125640 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
128195 INFO: Processing module hooks...
128202 INFO: Loading module hook 'hook-certifi.py' from 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
128229 INFO: Loading module hook 'hook-cv2.py' from 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
128250 INFO: Loading module hook 'hook-eel.py' from 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
128550 INFO: Loading module hook 'hook-pycparser.py' from 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
128561 INFO: Loading module hook 'hook-distutils.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
128578 INFO: Loading module hook 'hook-encodings.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
128821 INFO: Loading module hook 'hook-gevent.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
129953 INFO: Determining a mapping of distributions to packages...
140515 WARNING: Unable to find package for requirement zope.interface from package gevent.
140523 WARNING: Unable to find package for requirement greenlet from package gevent.
140537 WARNING: Unable to find package for requirement zope.event from package gevent.
140551 INFO: Packages required by gevent:
['setuptools', 'cffi']
142046 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
142244 INFO: Loading module hook 'hook-numpy.core.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
142511 INFO: Loading module hook 'hook-numpy.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
142524 INFO: Loading module hook 'hook-pkg_resources.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
143186 INFO: Processing pre-safe import module hook win32com from 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
143336 INFO: Processing pre-safe import module hook win32com from 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
143952 WARNING: Hidden import "pkg_resources.py2_warn" not found!
143961 WARNING: Hidden import "pkg_resources.markers" not found!
143981 INFO: Excluding import '__main__'
143994 INFO:   Removing import of __main__ from module pkg_resources
144006 INFO: Loading module hook 'hook-scipy.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
144037 INFO: Loading module hook 'hook-setuptools.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
145293 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
145301 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
145315 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
145334 INFO: Loading module hook 'hook-xml.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
145351 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
145918 INFO: checking Tree
145928 INFO: Building Tree because Tree-00.toc is non existent
145947 INFO: Building Tree Tree-00.toc
146141 INFO: checking Tree
146155 INFO: Building Tree because Tree-01.toc is non existent
146177 INFO: Building Tree Tree-01.toc
146323 INFO: Looking for ctypes DLLs
146554 INFO: Analyzing run-time hooks ...
146582 INFO: Including run-time hook 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
146605 INFO: Including run-time hook 'c:\\python\\python38-32\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\rthooks\\pyi_rth_certifi.py'
146626 INFO: Including run-time hook 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
146658 INFO: Including run-time hook 'c:\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
146705 INFO: Looking for dynamic libraries
149727 INFO: Looking for eggs
149739 INFO: Using Python library c:\python\python38-32\python38.dll
149761 INFO: Found binding redirects: 
[]
150841 INFO: Warnings written to C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\build\predictGUI\warn-predictGUI.txt
151113 INFO: Graph cross-reference written to C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\build\predictGUI\xref-predictGUI.html
151243 INFO: checking PYZ
151255 INFO: Building PYZ because PYZ-00.toc is non existent
151274 INFO: Building PYZ (ZlibArchive) C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\build\predictGUI\PYZ-00.pyz
151294 INFO: Building PYZ (ZlibArchive) C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\build\predictGUI\PYZ-00.pyz completed successfully.
151333 INFO: checking PKG
151346 INFO: Building PKG because PKG-00.toc is non existent
151364 INFO: Building PKG (CArchive) PKG-00.pkg
151835 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
151861 INFO: Bootloader c:\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw_d.exe
151881 INFO: checking EXE
151902 INFO: Building EXE because EXE-00.toc is non existent
151923 INFO: Building EXE from EXE-00.toc
151945 INFO: Appending archive to EXE C:\Users\Slaye\AppData\Local\Temp\tmpf0x1a0dk\build\predictGUI\predictGUI.exe
152233 INFO: Building EXE from EXE-00.toc completed successfully.
152267 INFO: checking COLLECT
152284 INFO: Building COLLECT because COLLECT-00.toc is non existent
152309 INFO: Building COLLECT COLLECT-00.toc
162717 INFO: Building COLLECT COLLECT-00.toc completed successfully.

Moving project to: D:\Internship\keras-video-classification\exe\output
Complete.

The script that I want to use is the following

from tkinter import *
import tkinter as tk
from keras.models import load_model
import os
from collections import deque
import numpy as np
import pickle
import cv2
import easygui
import ctypes
import requests
import json
boolHasCode = False
def run(outputName,entryCode,modelP,inputP,labelP,outputP,x,y):
    print("in Run")
    if('xyz' in entryCode or 'amr' in entryCode):
        runPredictor(outputName,modelP,inputP,labelP,outputP,x,y)
        print("running")
    else:
        print("well not today")




def runGet(x,modelP,inputP,labelP,outputP,classWanted,userId):
    ownerID = ''
    print(x)
    #fileSize = os.stat(inputP).st_size
    #fileName = os.path.basename(inputP)
    URL = "https://xxx.wixsite.com/corona/_functions/myFunction/"
    PARAMS = {'userId':x}
    r = requests.get(url=URL, params=PARAMS)
    data = r.json()
    #print(test)
    URLx = "https://xxx.wixsite.com/corona/_functions/testG/"
    #print("SECOND GET")
    #print("User ID is: ", userId)
    #print("File Name is:", fileName)
    #print("size",fileSize)
    #print("video class",classWanted)
    #PARAMSx = {
     #   'vidUserId':userId,
      #  'videoName':fileName,
       # 'videoSize':fileSize,
        #'videoClass':classWanted
   # }
    #y = requests.get(url=URLx, params=PARAMSx)
    #print("Status code", y.status_code)
    #datax = y.json()
    if ((data.get('not available') == 'ok')):
        #ctypes.windll.user32.MessageBoxW(0, "Code already used!", "ERROR!", 1)
        print("test")
    else:
        for i in data.get('items'):
            print("Code:",i['code'])
            manga = i['code']
            testGET.insert(0,i['code'])
            #ctypes.windll.user32.MessageBoxW(0, manga, "Code!", 1)
        print("in else")

    #print(r.text)


def runPut():
    r = requests.put('https://xxx.wixsite.com/corona/_functions-dev/functionPut/', data={'used':'true'})
    print(r)
    print(r.content)

modelP = ""
labelP = ""
inputP = ""
outputP = ""
def getModelPath():
    global modelP
    modelP = easygui.fileopenbox()
def getLabelPath():
    global labelP
    labelP = easygui.fileopenbox()
def getInputPath():
    global inputP
    inputP = easygui.fileopenbox()
def getOutputPath():
    global outputP
    outputP = easygui.diropenbox()



HEIGHT = 700
WIDTH = 800
root = Tk()
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

frame=tk.Frame(root, bg='gray')
frame.place(relx=0.11,rely=0.1,relwidth=0.75, relheight=0.7)







entryModelPath = tk.Entry(frame)
entryModelPath.place(relx=0.7,rely=0.1,relwidth=0.3,relheight=0.05)
entryModelPath.insert(0,'Enter Output Video Name!')
#button.place(relx=0.7,rely=0.1,relwidth=0.2,relheight=0.1)


label = tk.Button(frame, text="Model Path", bg="yellow",command=lambda : getModelPath())
label.place(relx=0.7,rely=0.3,relwidth=0.25,relheight=0.05)
#----------------------------
button2 = tk.Button(frame, text="Upload Label Pickle Path", bg="yellow", command=lambda : getLabelPath())
button2.place(relx=0.7,rely=0.4,relwidth=0.25,relheight=0.05)

#entryLabelPath = tk.Entry(frame)
#entryLabelPath.place(relx=0.3,rely=0.1,relwidth=0.3,relheight=0.05)
#----------------------------
label2 = tk.Button(frame, text="Video Path", bg="yellow", command=lambda : getInputPath())
label2.place(relx=0.7,rely=0.5,relwidth=0.25,relheight=0.05)

entryVideoPath = tk.Entry(frame, text="Enter Preferred Class")
entryVideoPath.place(relx=0.7,rely=0.15,relwidth=0.3,relheight=0.05)
entryVideoPath.insert(0,"Enter Preferred Class")

label3 = tk.Button(frame, text="Output Path", bg="yellow",command=lambda : getOutputPath())
label3.place(relx=0.7,rely=0.6,relwidth=0.25,relheight=0.05)




entryOutputPath = tk.Entry(frame)
entryOutputPath.place(relx=0.7,rely=0.2,relwidth=0.3,relheight=0.05)
entryOutputPath.insert(0,'Enter Code!')

button = tk.Button(frame, text="Predict", bg='red', command=lambda: run(entryModelPath.get(),entryOutputPath.get(),modelP,inputP,labelP,outputP,entryVideoPath.get(),testGET.get()))
button.place(relx=0.05,rely=0.8,relwidth=0.3,relheight=0.1)


testGET = tk.Entry(frame, bg="white")
testGET.place(relx=0.05,rely=0.1,relwidth=0.3,relheight=0.05)
testGET.insert(0,"Enter User ID")

button = tk.Button(frame, text="GET CODE", bg='gray', command=lambda:runGet(testGET.get(),modelP,inputP,labelP,outputP,entryVideoPath.get(),testGET.get()))
button.place(relx=0.1,rely=0.25,relwidth=0.2,relheight=0.1)





def runPredictor(outputName,modelP,inputP,labelP,outputP,classWanted,userId):

    print(modelP)
    print(inputP)
    print(labelP)
    print(outputP)
    fileSize = os.stat(inputP).st_size
    fileName = os.path.basename(inputP)
    print("starting with post")
    print("File size is:",fileSize)
    print("File name is:",fileName)
    print("User ID is:", userId)
    print("Class wanted is: ", classWanted)
    fileSizeToString = str(fileSize)
    print(type(userId))
    print(type(fileName))
    print(type(fileSizeToString))
    print(type(classWanted))
    objtwo = {}

    url = 'https://xxx.wixsite.com/corona/_functions/ggFunction/'
    myobj = {
        'vidUserId':userId,
        'videoName':fileName,
        'videoSize':fileSizeToString,
        'videoClass':classWanted
    }
    header = {'Content-Type': 'application/x-www-form-urlencoded'}

    PARAMS = {'vidUserId':userId,'vidName':fileName,'videoSize':fileSizeToString,'videoClass':classWanted}


    z = requests.post(url, data=json.dumps(PARAMS), headers=header)
    data = z.json()
    print(json.dumps(data, indent=2, sort_keys=True))
    print(z.status_code)
    print("done with post")




    model = load_model(modelP)
    lb = pickle.loads(open(labelP, "rb").read())
    mean = np.array([123.68, 116.779, 103.939][::1], dtype="float32")
    Q = deque(maxlen=1)
    vs = cv2.VideoCapture(inputP)
    writer = None
    (W, H) = (None, None)
    while True:
        (grabbed,frame) = vs.read()
        if not grabbed:
            break
        if W is None or H is None:
            (H, W) = frame.shape[:2]
        output = frame.copy()
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame = cv2.resize(frame, (224, 224)).astype("float32")
        frame -= mean
        preds = model.predict(np.expand_dims(frame, axis=0))[0]
        Q.append(preds)
        results = np.array(Q).mean(axis=0)
        i = np.argmax(results)
        label = lb.classes_[i]
        text = "activity: {}".format(label)
        cv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX,
                    1.25, (0, 255, 0), 5)
        if writer is None:
            # initialize our video writer
            sd =  outputP+outputName+".avi"
            print("output is to: ", sd)
            fourcc = cv2.VideoWriter_fourcc(*"MJPG")
            writer = cv2.VideoWriter(sd, fourcc, 30,
                                     (W, H), True)
        if (format(label) == classWanted):
            writer.write(output)
            print("writing output")
        cv2.imshow("Output", output)
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            break
    print("DONE")
    print("La done begad")
    writer.release()
    vs.release()
    #root.destroy()


root.mainloop()

#Tk().withdraw()
#filename = askopenfilename()
#print(filename)

When I try to open my GUI running the executable i get to see 3 different errors. Error1

Error2

Error3

Do note that I am running on an Anaconda environment. Python 3.7.

Thank you!

UPDATE#1

Tried --console instead of --windowed and console printed the following upon execution

https://0bin.net/paste/W6g9L39K#Y5unpfaMHVGj90BOpf+r7JHA23n7uNYQ105gwS6FV+7

UPDATE#3

Captured the error displayed in the console. Error in Console

  • Try not making it windowed, like compile to for console and that will print the error in the console when you run the code and include that with this Q – Delrius Euphoria Aug 26 '20 at 14:49
  • @CoolCloud Done. Updated the question with the console version – YourMomPlays Aug 26 '20 at 16:33
  • I must actually ask, why is the `--debug` flag set? are you sure, you need the debug? Why not just remove it and try again, ive complied tons of code using `pysinstaller` but never got such big lines in my console, maybe its the `--debug` – Delrius Euphoria Aug 26 '20 at 17:12
  • @CoolCloud I tried removing --debug and running a --windowed version and --console version. The windowed version only showed "Failed to execute script", the console version only opens the console for 3 seconds and closes automatically. – YourMomPlays Aug 26 '20 at 17:24
  • Yes your almost there, within the 3 seconds there is an error that pops up in the console(that causes it to close) you have to capture that somehow and that is your error code of python file and we can solve that later on. and im assuming you actualy have already copied the exe from `dist` folder on to your project directory – Delrius Euphoria Aug 26 '20 at 17:26
  • @CoolCloud Added the console log – YourMomPlays Aug 27 '20 at 01:31
  • Take a look at these, [First](https://stackoverflow.com/questions/62465620/error-keras-requires-tensorflow-2-2-or-higher) and [Second](https://github.com/streamlit/streamlit/issues/1613) – Delrius Euphoria Aug 27 '20 at 06:34
  • When you say "standalone executable file" do you mean a single .exe file? Because --onedir creates a directory bundle with dependencies not bundled into the .exe file, --onefile is the flag that bundles into a single .exe file – Jim Zhou Aug 27 '20 at 07:54
  • @JimZhou I tried --onefile. It gives the same error. – YourMomPlays Aug 27 '20 at 13:39
  • @CoolCloud Tried both, nothing worked:/ – YourMomPlays Aug 27 '20 at 13:42
  • Does --onefile actually give you the output format in terms of the .exe file at least? Or did both --onedir and --onefile also produce the same file as output? Furthermore, can you try running the original command, except with --onefile, but also --clean and --hidden-import tensorflow and see if that works? – Jim Zhou Aug 27 '20 at 13:58
  • @YourMomPlays that is sad, but tensorflow is the issue maybe `--hidden-import` it like Jim said – Delrius Euphoria Aug 27 '20 at 14:11
  • @JimZhou It produces a single .exe file. I tried this "pyinstaller --noconfirm --onefile --windowed --clean --debug "all" --hidden-import "tensorflow" "D:/Internship/keras-video-classification/predictGUI.py"" and it showed "Cannot execute script pyiboot01-bootstrsap. Im getting really frustrated with this :/ – YourMomPlays Aug 27 '20 at 14:13
  • `--noconfirm` and `--debug` why are you using it? – Delrius Euphoria Aug 27 '20 at 14:15
  • @CoolCloud Removed this. Still same error – YourMomPlays Aug 27 '20 at 14:35
  • Without "--debug" it still throws "Cannot execute script pyiboot01-bootstrap"? – Jim Zhou Aug 27 '20 at 14:36
  • Now, i believe asking this Q in github for pyinstaller is more accurate, as the "professional help from the moderators might be recieved" – Delrius Euphoria Aug 27 '20 at 14:39
  • Forgot to mention: --windowed will suppress most error messages, so for now you may want to get rid of that (also defeats the purpose of the print() calls). --loglevel=DEBUG will then log debug messages. Pyinstaller usually doesn't throw proper errors for dependency issues, but debugging messages and some of the debugging output files should. – Jim Zhou Aug 27 '20 at 14:55

0 Answers0