Python:cx_Freeze .exe不起作用& .py文件工作正常

时间:2015-11-10 08:38:06

标签: python matplotlib charts exe cx-freeze

我一直在研究这个小工具来分析我们的票证数据库。

my GUI

主要目标是1.选择一个pickle文件,其中包含许多字典,如下所示:

2458 {'origin': u'HW', 
'department': u'Kunde', 
'ticket-closed': True, 
'prio-events': [(datetime.datetime(2015, 4, 27, 16, 53, 55, 77779, tzinfo=<LocalTimezone "UTC+02:00" 2:00:00>), u'Wichtig')], 
'status-events': [(datetime.datetime(2015, 4, 27, 16, 53, 55, 77779, tzinfo=<LocalTimezone "UTC+02:00" 2:00:00>), u'new'), 
(datetime.datetime(2015, 5, 15, 15, 12, 53, 29570, tzinfo=<LocalTimezone "UTC+02:00" 2:00:00>), u'closed')]}



2459 {'origin': u'HW', 
'department': u'Kunde', 
'ticket-closed': True, 
'prio-events': [(datetime.datetime(2015, 4, 27, 16, 53, 55, 94126, tzinfo=<LocalTimezone "UTC+02:00" 2:00:00>), u'W\xfcnschenswert')], 
'status-events': [(datetime.datetime(2015, 4, 27, 16, 53, 55, 94126, tzinfo=<LocalTimezone "UTC+02:00" 2:00:00>), u'new'), 
(datetime.datetime(2015, 5, 11, 14, 47, 28, 916677, tzinfo=<LocalTimezone "UTC+02:00" 2:00:00>), u'closed')]}
  1. 将数据分隔在不同的词典中(创建,关闭,打开)
  2. 使用matplotlib在饼图中显示我的数据。
  3. mpl_figure

    你可以看到一切正常,直到这里。之后,我想创建一个.exe,这样我就可以在其他计算机上使用我的工具了。

    我设法使用cx_Freeze创建.exe。它运行完美但我没有得到任何有用的结果,我不知道我做错了什么。

    figure_2

    这就是我的setup.py看起来的样子:

    import cx_Freeze
    import sys
    import matplotlib
    import pickle
    from Tkinter import *
    from tkFileDialog   import askopenfilename
    import numpy as np
    import matplotlib.pyplot as plt
    from datetime import datetime
    import os
    from PIL import Image, ImageTk
    
    base = None
    
    if sys.platform == 'win32':
        base = "Win32GUI"
    
    executables = [cx_Freeze.Executable("ticketanalysis.py", base=base, icon = "Iconka-Saint-Whiskers-Cat-cupid-love.ico")]
    
    cx_Freeze.setup(
        name = "Ticketauswertung CX_FREEZE",
        options = {"build_exe" : {"packages":["Tkinter","matplotlib", "numpy", "PIL", "os", "pickle", "datetime", "xlwt", "tkFileDialog"], "include_files":["Iconka-Saint-Whiskers-Cat-cupid-love.ico"]}},
        version = "0.01",
        description = "Ticketanalysissoftware by KH",
        executables = executables
        )
    

    这是我的代码:

    import pickle
    from Tkinter import *
    from tkFileDialog   import askopenfilename
    import numpy as np
    import matplotlib.pyplot as plt
    from datetime import datetime
    import os
    from PIL import Image, ImageTk
    
    datanameString = ''
    datapathString = ''
    ClosedDict = {}
    OpenDict = {}
    CreatedDict = {}
    ClosedList = [0] * 53
    OpenList = [0] * 53
    CreatedList = [0] * 53
    
    ################################################################################
    #Methods
    
    def getDataname():    
        global datanameString
        global CreatedList
        global OpenList
        global ClosedList
        global datapathString
    
        CreatedList = [0] * 53
        OpenList = [0] * 53
        ClosedList = [0] * 53
        ClosedDict.clear()
        OpenDict.clear()
        CreatedDict.clear()
    
        datapathString = askopenfilename()
        datanameString = os.path.basename(datapathString)
    
        l3 = Label(root, text='').grid(row=1, column=0, sticky=W+E+N+S)
        l3 = Label(root, text=datanameString).grid(row=1, column=0, sticky=W+E+N+S)
    
        print "FILENAME CHOSEN!"
    
    def SeperateData(pickle_filename):
        freshpickle = pickle.load(open(pickle_filename, 'rb'))
    
        ClosedDict.clear()
        OpenDict.clear()
        CreatedDict.clear()
    
        for (i,j) in freshpickle.iteritems():
            if j['ticket-closed'] == True:
                ClosedDict[i] = j
                CreatedDict[i] = j
    
        for (i,j) in freshpickle.iteritems():
            if j['ticket-closed'] == False:
                OpenDict[i] = j
                CreatedDict[i] = j
    
        print "SEPERATING DATA FINISHED!"
    
    def ShowPieChart():
        internCounter = 0
        kundeCounter = 0
        newCounter = 0
        closedCounter = 0
        developingCounter = 0
        testingCounter = 0
        tbdCounter = 0
        HWCounter = 0
        SWCounter = 0
        tClosedCounter = 0
        tOpenCounter = 0
    
        for (i,j) in CreatedDict.iteritems():
            if j['status-events'][-1][-1] == 'new':
                newCounter += 1
            if j['status-events'][-1][-1] == 'closed':
                closedCounter += 1
            if j['status-events'][-1][-1] == 'developing':
                developingCounter += 1
            if j['status-events'][-1][-1] == 'testing':
                testingCounter += 1
            if j['status-events'][-1][-1] == 'tbd':
                tbdCounter += 1
    
        plt.style.use('ggplot')
        fig = plt.figure()
    
        labels = ('new', 'closed', 'developing', 'testing', 'tbd')
        sizes = [newCounter, closedCounter, developingCounter, testingCounter, tbdCounter]
        colors = ['#F5FC34', '#52FC34', '#FAAB23', '#237DFA', '#C863FA', ]
        explode = (0, 0, 0, 0, 0) 
        ax1 = fig.add_subplot(2,2,1)
        ax1.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
        ax1.set_title("Anforderungen: Status")
    
        for (i,j) in CreatedDict.iteritems():
            if j['department'] == 'Intern':
                internCounter += 1
            if j['department'] == 'Kunde':
                kundeCounter += 1
    
        ax2 = fig.add_subplot(2,2,2)            
        labels = ('Intern', 'Kunde')
        sizes = [internCounter, kundeCounter]
        colors = ['#FAF063', '#63BBFA']
        explode = (0, 0) 
        ax2.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
        ax2.set_title("Anforderungen: Department")
    
        for (i,j) in CreatedDict.iteritems():
            if j['origin'] == 'HW':
                HWCounter += 1
            if j['origin'] == 'SW':
                SWCounter += 1
    
        ax2 = fig.add_subplot(2,2,3)            
        labels = ('HW', 'SW')
        sizes = [HWCounter, SWCounter]
        colors = ['#6A0D7D', '#503C3C']
        explode = (0, 0) 
        ax2.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
        ax2.set_title("Anforderungen: Origin")
    
        for (i,j) in CreatedDict.iteritems():
            if j['ticket-closed'] == True:
                tClosedCounter += 1
            if j['ticket-closed'] == False:
                tOpenCounter += 1
    
        ax2 = fig.add_subplot(2,2,4)            
        labels = ('Closed', 'Open')
        sizes = [tClosedCounter, tOpenCounter]
        colors = ['#58FB4C', '#F8183A']
        explode = (0, 0) 
        ax2.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
        ax2.set_title("Anforderungen: Closed-Status")
    
        figManager = plt.get_current_fig_manager()
        figManager.window.showMaximized()
        plt.show()
    
    ################################################################################
    #GUI
    
    root = Tk() 
    root.title("Ticketanalysis v1.0")
    root.geometry("350x340")
    
    
    l1 = Label(root, text="Ticketanalysis by KH\n", width=50).grid(row=0, column=0, sticky=W+E+N+S)
    l2 = Label(root, text="", width=50).grid(row=1, column=0, sticky=W+E+N+S)
    b1 = Button(root, text='Choose File', command = getDataname, width=50).grid(row=2, column=0, sticky=W+E+N+S)
    b2 = Button(root, text='Seperate Data', command = lambda: SeperateData(datapathString), width=50).grid(row=3, column=0, sticky=W+E+N+S)
    b7 = Button(root, text='ShowPieChart', command = ShowPieChart, width=50).grid(row=8, column=0, sticky=W+E+N+S)
    
    mainloop()    
    
    ################################################################################
    

    我知道我的代码并不完美,但我只是要求你帮我把.exe工作正常。

    谢谢!

0 个答案:

没有答案