减少Pyinstaller exe文件的大小

时间:2019-08-30 15:58:14

标签: python-3.x pyinstaller

我正在使用的库如:Pandas,tkinter,sqlite3,datetime,openpyxl和win32api。 是否可以从 *。spec 文件中排除这些库中的任何一个以减小当前exe文件的大小?

exe文件的当前大小为320MB。

我试图从这些库中排除一些库,但此后我的应用程序无法正常工作。

# -*- coding: utf-8 -*-
from tkinter import Frame, Label, Entry, Button, Message, StringVar, IntVar, Tk
import tkinter.ttk as ttk
import win32api
from datetime import datetime
from openpyxl import load_workbook
import sqlite3
import pandas as pd

class MainApp():
    def __init__(self, master):    
        self.master=master
        master.title("Daily Tracker")
        self.frame=Frame(master)
        master.config(bg="snow3")
        master.geometry("490x300+10+10")
        master.resizable(False,False)

        #Retrive system logged in name
        self.username=StringVar()
        self.username=win32api.GetUserNameEx(3)

        #User Name Auto Generate 1/1
        Label(master, text="User Name:", bg="snow3", fg="black", font=("calibri",11)).place(x=20, y=30)
        self.lblEmpNme=Label(master, bg="snow3", fg="dark green", font=("calibri",11,'bold'))

        #Employee ID Field 1/2
        Label(master, text="Emp ID:", bg="snow3", fg="black", font=("calibri",11)).place(x=310, y=30)
        self.lblEmpID=Label(master, bg="snow3", fg="dark green", font=("calibri",11,"bold"))

        #Process Name Select Option 1/1
        Label(master, text="Process Name:", bg="snow3", fg="black", font=("calibri",11)).place(x=20, y=70)
        self.cbProcess=ttk.Combobox(master, width=35, state="readonly", values=['Reinsurance-IT Support','ERDR Implimentation','Raiders 2 Support','Reinsurance BA & Testing Support'])
        self.cbProcess.place(x=130, y=70)
        self.cbProcess.current(0)

        #Task Name Select Option 1/1
        Label(master, text="Task Name:", bg="snow3", fg="black", font=("calibri",11)).place(x=20, y=100)
        self.cbTask=ttk.Combobox(master, width=35, state="readonly", values=["Access Database Queries", "BRD Creation/Update", "Cession Testing", "Data Template - BRD", "ERDR Assigning Treaty ID & DOC ID", "ERDR COV - Rein Code & G/L Update", "ERDR Monthly Update - Preparation & Testing", "ERDR Web Portal Access Management", "Error Log Update", "Error Reports", "GOSC Team Meeting", "High Volume Testing", "Minutes Of Meeting", "Miscellaneous/Others", "Model Testing", "Monthly Reports - Raiders 2", "PolFact Testing", "Policy Research", "Project Meeting", "SharePoint Task/Monthly Log Maintenance", "SOP Creation/Modification", "Team Application Access Status - Bi Monthly", "Team Update Tracker", "Template Coding", "Training", "Treaty Grid", "Treaty Master List Checking", "UW Rates Expansion", "Validate DB2 Tables - Eric's Testing", "Other"])
        self.cbTask.place(x=130, y=100)
        self.cbTask.current(0)

        #Project Name Select Option 1/1
        self.txProjectVal=StringVar()
        Label(master, text="Project Name:", bg="snow3", fg="black", font=("calibri",11)).place(x=20, y=130)
        self.txtProject=Entry(master, width=33, bg="linen", font=("calibri",11), textvariable=self.txProjectVal)
        self.txtProject.place(x=130, y=130)

        #Button Area
        self.btnStart=Button(master, text="Start", width=11, bg="navy", fg="white",font="calibri 10 bold", command=self.startTime)
        self.btnStart.bind("<Return>", (lambda event: self.startTime()))
        self.btnStart.place(x=40, y=182)

        self.btnStop=Button(master, text="Stop", width=11, bg="navy", fg="white",font="calibri 10 bold", command=self.endtTime)
        self.btnStop.bind("<Return>", (lambda event: self.endtTime()))
        self.btnStop.place(x=200, y=182)

        self.btnQuit=Button(master, text="Quit", width=11, bg="navy", fg="white",font="calibri 10 bold", command=master.destroy)
        self.btnQuit.bind("<Return>", (lambda event: master.destroy()))
        self.btnQuit.place(x=350, y=182)

        #Creating the SQLite3 connection to fetch the Employee ID and validating whether user is added or not
        dbpath=r'\\C:\Users'
        conn=sqlite3.connect(dbpath + r'\EmpRecords.db')
        c=conn.cursor()
        c.execute("SELECT empName FROM tblEmpDetails WHERE empName = '{}'".format(self.username))
        if c.fetchone() is None:
            Message(master, width=480,text="You are not authorized. Please contact Santosh Kumar",bg="snow3", fg="red", font=("calibri",11,"bold")).place(x=50, y=270)
            self.cbProcess['state']=DISABLED
            self.cbTask['state']=DISABLED
            self.txtProject['state']=DISABLED
            self.btnStart['state']=DISABLED
            self.btnStop['state']=DISABLED
            c.close()
            conn.close()
        else:
            for row in c.execute("SELECT empName, empID FROM tblEmpDetails WHERE empName = '{}'".format(self.username)):
                user=list(row)
                if user[0] == self.username:
                    self.lblEmpNme['text']=user[0]
                    self.lblEmpNme.place(x=130,y=30)
                    self.lblEmpID['text']=user[1]
                    self.lblEmpID.place(x=365, y=30)                
            c.close()
            conn.close()

        # Time related labels
        Label(master, text="Start Time:", bg="snow3", fg="black", font=("calibri",11)).place(x=45, y=220)
        Label(master, text="End Time:", bg="snow3", fg="black", font=("calibri",11)).place(x=210, y=220)
        Label(master, text="Total Time:", bg="snow3", fg="black", font=("calibri",11)).place(x=355, y=220)
        self.lbStartTime=Label(master, bg="snow3", fg="navy", font=("calibri",9))
        self.lbEndTime=Label(master, bg="snow3", fg="navy", font=("calibri",9))
        self.lbTotalTime=Label(master, bg="snow3", fg="navy", font=("calibri",9))

    def startTime(self):
        self.now=datetime.now().replace(microsecond=0)
        self.st=self.now
        self.lbStartTime['text']=self.now.strftime("%d/%m/%Y %H:%M:%S")
        self.sdate=datetime.now().date()
        self.stime=datetime.now().replace(microsecond=0)

        self.lbStartTime.place(x=30, y=240)

        # Clear all the values after clicking Stop button
        self.lbEndTime['text']=""
        self.lbTotalTime['text']=""

    def endtTime(self):
        self.now=datetime.now().replace(microsecond=0)
        self.et=self.now
        self.lbEndTime['text']=self.now.strftime("%d/%m/%Y %H:%M:%S")
        self.edate=datetime.now().date()
        self.etime=datetime.now().replace(microsecond=0)

        self.lbEndTime.place(x=185, y=240)
        self.lbTotalTime['text']=(self.et-self.st)
        self.lbTotalTime.place(x=365, y=240)

        self.exlEntry()

    def exlEntry(self):
        dbpath=r'C:\Users'
        filenme=dbpath + '\\' + self.username +'.xlsx'
        A=[]

        for i in range(0,1):
            A.append([])
            for j in range(0,1):
                A[i].append(self.sdate)                 #Date
                A[i].append(self.stime)                 #TIME
                A[i].append(self.username)              #USER NAME
                A[i].append(self.lblEmpID['text'])      #EMP ID
                A[i].append(self.txProjectVal.get())    #PROJECT NAME
                A[i].append(self.cbTask.get())          #TASK NAME
                A[i].append(" ")                        #OTERS
                A[i].append(self.cbProcess.get())       #RELETED TO..
                A[i].append(self.stime)                 #START DATE
                A[i].append(self.etime)                 #STOP TIME
                A[i].append((self.etime-self.stime))    #Duration

        df=pd.DataFrame(A)
        # columns=['Date','TIME','USER NAME','EMP ID','PROJECT NAME','TASK NAME','OTERS','RELETED TO..','START DATE','STOP TIME','Duration']
        writer=pd.ExcelWriter(filenme, engine='openpyxl', datetime_format='h:mm:ss AM/PM', date_format='dd-mm-yyyy')
        writer.book=load_workbook(filename=filenme)
        lastrow=writer.book["Sheet1"].max_row
        writer.sheets={ws.title:ws for ws in writer.book.worksheets}
        df.to_excel(writer, "Sheet1", header=False, startrow=lastrow, index=False)
        writer.save()

if __name__=='__main__':
    app=Tk()
    my_gui=MainApp(app)
    app.mainloop()

我想减小exe文件的大小。

0 个答案:

没有答案