Executable will run on any computer, but will only preform properly my computers with python

Viewed 31

I'm an intern and I'm trying to make a simple lookup script for my company that will take a SQL database and search through it to make a more user readable list. I got the script to do roughly what I want and am now trying to make an executable that people in my office can try out. The problem is that the script seems to only preform as intended on machines with python. The script will open on the PC every PC, but when I feed it the SQL file it does not populate the text field.

I tried using pyinstaller, py2exe, and python build -> (python file.py build) with no luck. I followed Reedinationers compile guide here. My python exe will not run 2 other python exe's

import re
import tkinter as tk
from tkinter.filedialog import askopenfilename
from _sqlite3 import Error
from tkinter import PhotoImage


#          Link the .DB file
###########################################
def create_connection(db_file):
    try:
        conn = _sqlite3.connect(db_file)
        return conn
    except Error as e:
        print(e)
    return None
###########################################
try:
    UserFile = open("UserFriend.txt", "w")
                                            #Check for File if one does not exist make it
except:
    UserFile = open("UserFriend.txt", "w+")
###########################################
global Error
Error = False
###########################################
def Friendly_Output(line, number, times, Error_Finder, Time_Stamp, Search_Count):
    #Error_List = []
    #setup = []
    #print(Search_Count)
    ############################################################################
    if "viewDidLoad() - Got a valid" in line and Error == False:
        setup.append("\nFound mac address here \t\t\t\t\t| "+ Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and "wifiScanTimerEvent(timer:)" in line:
        #UserFile.write("\nPinged nearby wifi with NIC " + str(times) + " time(s)")
        if times >= 10:
            spacing = " \t| "
        else:
            spacing = "\t\t\t| "
        setup.append("\nPinged nearby wifi with NIC " + str(times) + " time(s)" + spacing + Time_Stamp)
        ########################################################
    if Error == False and "rssi:" in line:
        strength = line[15:18]
        if int(strength) >= -30:
            Sname = "Excellent"
            space = "\t\t\t\t\t| "
        if int(strength) <= -30 and int(strength) >=-64:
            Sname = "Very Good"
            space = "\t\t\t\t\t| "
        elif int(strength) <= -64 and int(strength) >=-70:
            Sname = "Okay"
            space = "\t\t\t\t\t| "
        elif int(strength) <= -70 and int(strength) >=-80:
            Sname = "Bad"
            space = "\t\t\t\t\t| "
        elif int(strength) <= -80 and int(strength) >=-90:
            Sname = "Useless"
            space = "\t\t\t\t\t| "
        else:
            pass
        setup.append("\nThe signal strength is " + Sname + space + Time_Stamp)
    else:
        pass



    if Error == False and "refrigeratorTapped()" in line:
        #UserFile.write("\nTransfer to Pin Entry")
        setup.append("\nTransfer to Pin Entry Screen \t\t\t\t\t| " + Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and "applianceTapped() - segue_to_wifi_select_sid" in line:
        #UserFile.write("\nTransfer to wifi selection page")
        setup.append("\nTransfer to wifi selection page \t\t\t\t\t| " + Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and "prepare(for:sender:) - segue_to_prod_wifi_setup_sid" in line:
        #UserFile.write("\nTransfer to Wifi crediental entry screen")
        setup.append("\nTransfer to Wifi crediental screen \t\t\t\t | " + Time_Stamp)
    else:
        pass
    if Error == False and "addWifiNameToParamOut(wifi:)" in line:
        #UserFile.write("\nAdded wifi to data send list")0
        setup.append("\nAdded wifi to data send list \t\t\t\t\t| " + Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and "setDevicePrivilegeCloud(macAddress:userApiKey:devicePin:privilegeCompletionHandler:) - Called with" in line:
        #UserFile.write("\nSent MacAddress, apiKey, and devicePin to Cloud")
        setup.append("\nSent device information to Cloud \t\t\t\t\t| " + Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and r"setDevicePrivilegeCloud(macAddress:userApiKey:devicePin:privilegeCompletionHandler:) - \nDevice" in line:
        #UserFile.write("\nSuccessful sending of  MacAddress, apiKey, and devicePin to Cloud")
        setup.append("\nSuccessful sending of  MacAddress, apiKey, and devicePin to Cloud @ " + Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and "onRecordButton" in line:
        #UserFile.write("\nEntry applied to appliance list (Continue Button)")
        setup.append("\nEntry applied to appliance list\t\t\t\t\t| " + Time_Stamp)
    else:
        pass
        ########################################################
    if Error == False and "updateApplianceRecord() - upda" in line:
        #UserFile.write("\nUser notified of success")
        #UserFile.write("\nEnd of Setup number: " + str(number) + "\n\n")
        setup.append("\n\t\t\t\t\t|\nEnd of Setup number: " + str(number)+ "\t\t\t\t\t| " + "\nUser notified of success \t\t\t\t\t| " + Time_Stamp)
        #Error_List.append("\n\nEnd of Setup number: " + str(number)+ "\nUser notified of success @ " + Time_Stamp)
    else:
        pass
                #ERROR GRABS
#######################################################################################

    if   "0110" in line:
        #UserFile.write("\nERROR: No Bluetooth device was found")
        setup.append("\nERROR: No Bluetooth device was found \t\t\t| " + Time_Stamp)
        Error_List.append("\nERROR: No Bluetooth device was found \t\t\t| " + Time_Stamp)
    elif "ErrorCode: loginCloudNew" in line:
        setup.append("\nIncorrect Username or password attempt\t | " + Time_Stamp)
        Error_List.append("\nIncorrect Username or password attempt\t | " + Time_Stamp)
    elif "0120" in line:
        #UserFile.write("\nERROR: No Wifi or Poor Connection")
        setup.append("\nNo Wifi or Poor Connection \t\t\t\t\t| " + Time_Stamp)
        Error_List.append("\nNo Wifi or Poor Connection \t\t\t\t\t| " + Time_Stamp)
    elif "0130" in line:
        #UserFile.write("\nERROR: User searched for appliance but none was found")
        setup.append("\nSearched for appliance nothing was found| "+ Time_Stamp)
        Error_List.append("\nSearched for appliance nothing found\t\t\t\t| " + Time_Stamp)
    elif "300" in line:
        #UserFile.write("\nERROR: Wifi List is empty. Restarting configure process.")
        setup.append("\nWifi List is empty. \t\t\t\t\t| " + Time_Stamp)
        Error_List.append("\nWifi List is empty. \t\t\t\t\t| " + Time_Stamp)
    elif "310" in line:
        #UserFile.write("\nERROR: Lost BluetoothConnection in Wifi Picker Screen. Restarting configure process.")
        setup.append("\nBluetooth Connection lost on WiFi screen| " + Time_Stamp)
        Error_List.append("\nBluetooth Connection lost on WiFi screen| " + Time_Stamp)
    elif "1010" in line:
        #UserFile.write("\nERROR: User opted to skip wifi Setup")
        setup.append("\nUser opted to skip wifi Setup at\t\t\t\t\t| " + Time_Stamp)
        Error_List.append("\nERROR: User opted to skip wifi Setup\t\t\t\t| " + Time_Stamp)
    elif "1011" in line:
        #UserFile.write("\nERROR: There was an empty text field when trying to configure wifi")
        setup.append("\nUser left text field empty \t\t\t\t\t| " + Time_Stamp)
        Error_List.append("\nUser left text field empty \t\t\t\t\t| " + Time_Stamp)
    elif "1012" in line:
        #UserFile.write("\nERROR: Bluetooth Disconnected, Reason Unknown")
        setup.append("\nBluetooth Disconnected, Reason Unknown \t| " + Time_Stamp)
        Error_List.append("\nBluetooth Disconnected, Reason Unknown \t| " + Time_Stamp)
    elif "1013" in line:
        #UserFile.write("\nERROR: The provision watchdog timer has timed out without response from NIC")
        setup.append("\nUser experienced connection timeout \t\t\t\t| " + Time_Stamp)
        Error_List.append("\nUser experienced connection timeout \t\t\t\t| " + Time_Stamp)
    elif "1029"  in line:
        #UserFile.write("\nERROR: The Cloud Service reports error. Error in log")
        setup.append("\nThe Cloud Service reports error.\t\t\t\t\t| " + Time_Stamp)
        Error_List.append("\nThe Cloud Service reports error.\t\t\t\t\t| " + Time_Stamp)
    elif "1030" in line:
        #UserFile.write("\nERROR: The provisioning has failed.  The device and apikey key were not returned")
        setup.append("\nDevice and apikey key were not returned | " + Time_Stamp)
        Error_List.append("\nDevice and apikey key were not returned | " + Time_Stamp)
    if Search_Count == Loop_Count-2:
        Search_Func(Error_List,setup,Error_Finder,Search_Count)

#Need to clear the Error_List when the Error Locator button is press when it is press it is running search again and adding the the errors back as a 2nd duplicate
################################################################################################
def Search_Func(Error_List, setup, Error_Finder,Search_Count):
    if Error_Finder == True:
        if not Error_List:
            Text_Box.insert('1.0',"There are no Errors Found")
        for text in reversed(Error_List):
            Text_Box.insert('1.0', text)
            UserFile.write(text)
    else:
        for text in setup:
            Text_Box.insert('1.0', text)
            UserFile.write(text)
#Main Function (cursor setup, variables for count ping and hits)
################################################################################
def main(filename,Error_Finder):
    list = create_connection(filename)  # create_connection(database)
    global Loop_Count
    cur = list.cursor()
    cur.execute("SELECT * from error_log ")
    rows = cur.fetchall()
    count = 0
    Search_Count = 0
    pings = 1
    hits = 0
    info = []
    Loop_Count = rows[:]
    Loop_Count = len(Loop_Count)
    for row in rows:
        info.append(row[2])
#Regex Grab
#########################################################################
    m = re.search(r"(?s)id: (?P<username>.+?) - (?P<password>.+?)'.*Appliance: (?P<modelnumber>\S+).*macAddress: (?P<macaddress>.+?)'.*appl name: (?P<applname>\S+)", str(info))
    if (info): #                              - (?P<password>.+?)'.*App...
        try:
            if Error_Finder == False:
                UserFile.write(           'Username: {}, Modelnumber: {}, Macaddress: {}, applname: {}\n\n'.format(m.group('username'),m.group('modelnumber'),m.group('macaddress'),m.group('applname')))
                Text_Box.insert('1.0','\n\nUsername:\t\t {}\nModelnumber:\t\t {}\nMacaddress:\t\t {}\napplname:\t\t {}\n\n'.format(m.group('username'),m.group('modelnumber'),m.group('macaddress'),m.group('applname')))
#Search counters and Callers                              Password: {},
#########################################################################
            count = 0 # reset count
            pings = 1 # reset pings
            hits =  0 # reset hits
            for row in rows:
                Search_Count += 1
                Friendly_Output(str(row[2]), count, pings, Error_Finder,str(row[1]),Search_Count)
                info.append(row)
                if "onRecordButton - Calling" in str(row):
                    count += 1
                    pings = 1
                if "wifiScanTimerEvent(timer:)" in str(row):
                    pings = pings + 1
        except:
            print("Type None Occured")
# GUI
################################################################################
window = tk.Tk()
window.title("Viking Range SuChef Diagnostics")
width_value = window.winfo_screenwidth()
height_value = window.winfo_screenheight()
window.geometry(f"{width_value}x{height_value}+0+0")
text_height = 50#height_value/20
text_width = 115#width_value/9.05
photo = PhotoImage(file = "glass-teal.png")
background_image=tk.PhotoImage(file = "glass-teal.png")
background_image = background_image.zoom(2)
background_label = tk.Label(window, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)

def Load_File():
    global fname
    global Error_Finder
    global Error_List
    global setup
    Error_List = []
    setup = []
    fname = askopenfilename(filetypes = (("SQL Database", "*.db"),  ("All Files","*.*")))
    Text_Box.delete(1.0,tk.END)
    Error_Finder = False
    main(fname, Error_Finder)
    return fname

def Clear_Log():
    Text_Box.delete(1.0,tk.END)

def Find_Errors():
    try:
        if fname:
            Text_Box.delete(1.0,tk.END)
            Error_Finder = True
            Search_Func(Error_List, None, Error_Finder,None)
    except:
        Text_Box.insert('1.0', "You must First select a File")

def ViewFunc():
    try:
        if fname:
            ErrorFinder = False
            Text_Box.delete(1.0,tk.END)
            Search_Func(None, setup, Error_Finder, None)
    except:
        Text_Box.insert('1.0', "You must first select a File")

#Label
label = tk.Label(text = "Viking Range Service Application", font = "Arial") #fg = "blue"
label.pack()#grid(column = 0, row = 0)

#Browse_Button
Browse_Button = tk.Button(text = "Browse Files",cursor="cross", command = Load_File)
Browse_Button.pack()#grid(column = 0, row = 1)
Clear_Button = tk.Button(text = "Clear", command = Clear_Log)
Clear_Button.pack()#grid(column = 0, row = 1)
#Text field
Text_Box = tk.Text(height = int(text_height), width = int(text_width), background = "black", foreground = "white")
#Text_Box.place(anchor = tk.CENTER)
Error_Button = tk.Button(text = "Error Locator", command = Find_Errors)
Full_DocB = tk.Button(text = "View Full Document", command = ViewFunc)
Error_Button.pack()#grid(column = 0, row = 1)
Full_DocB.pack()
Text_Box.pack()#grid(column = 0, row = 2)

window.mainloop()
############################################################################################

The expected process to launch the .exe browse for SQL file select it and receive a readable output in the black text box and a file is saved with nearly the same text. What is happening is that a User can launch and select a file but the text box is never populated and the file is created, but it is empty.

0 Answers
Related