2016-07-27 59 views
0

我正在開發一個使用Python 3.4和PyQt4與LiClipse作爲IDE的應用程序,並有繪圖關閉整個程序沒有錯誤後,我編譯到可執行文件的程序後出現問題。我已經指出了問題領域,並知道調用matplotlib.figure.Figure()是崩潰的罪魁禍首,但我不知道從哪裏去。EXE與MatplotLib崩潰

import matplotlib 
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 
from matplotlib.figure import Figure 
class GraphWidget(FigureCanvas): 
    def __init__(self,parent=None,width = 500, height = 600, dpi = 100): 

     self.width = width/dpi 
     self.height = height/dpi 
     self.dpi = dpi 

     #================crashes here=============# 
     self.figure = Figure((self.width,self.height), dpi=self.dpi) 
     #=========================================# 

     alert = QMessageBox() 
     alert.setText("Passed Figure()") 
     alert.exec_() 

     FigureCanvas.__init__(self,self.figure) 
     alert = QMessageBox() 
     alert.setText("Passed super init") 
     alert.exec_() 

     self.canvas = self 
     self.axis = self.figure.add_subplot(111) 
     self.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding) 
     self.parent = parent 

    def set_new_graph(self,data,labels): 
     self.layoutVert = QVBoxLayout(self) 
     size = QSize(self.width*self.dpi,self.height*self.dpi) 

     self.axis.hold(False) 

     mined = min(data.totalamount) - round(min(data.totalamount)*.1,0) 
     if mined > 0: mined = 0 
     maxed = max(data.totalamount) + round(max(data.totalamount)*.1,0) 
     if maxed == mined: maxed += 5 

     data.plot(x = data.totalamount 
        , ax = self.axis 
        , kind = 'bar' 
        , rot=0 
        , legend = False 
        , sharex = True 
        , sharey = True 
#     , xticks = labels 
        , ylim = (mined,maxed) 
        , table = False) 
#   self.axis.set_ylim(mined,maxed) 
     self.axis.set_xticklabels(labels, fontsize = 'small') 

     self.axis.set_title("Sales History over Past Year") 
     self.canvas.draw() 
     self.resize(size) 
     self.layoutVert.addWidget(self.canvas) 

我py2exe的安裝腳本生成的所有功能時的曲線在頁面上初始化,除了一個可用的可執行文件:

mpld = matplotlib.get_py2exe_datafiles() 
include = ['sip','pandas','reportlab' 
     , 'PyQt4' 
     , 'PyQt4.QtGui' 
     , 'PyQt4.QtCore' 
     , 'PyQt4.Qt' 
     ,'reportlab.rl_settings','scipy','win32com' 
     ,'win32com.client' 
     , 'matplotlib' 
     , 'matplotlib.backends' 
     , 'matplotlib.backends.backend_qt4agg' 
     , 'matplotlib.figure' 
     ] 

exclude = ['nbformat','win32com.gen_py',"six.moves.urllib.parse", 
    '_gtkagg', '_tkagg', '_agg2', 
    '_cairo', '_cocoaagg', 
    '_fltkagg', '_gtk', '_gtkcairo'] 

setup(name="ServiceMgmt", 
     # console based executables 
     console=[], 

     # windows subsystem executables (no console) 
     windows=['ServiceMgmt.py'], 

     # py2exe options 
     #zipfile=None, 
     options={"py2exe": py2exe_options}, 
     data_files=mpld 
     ) 

我能夠運行我的應用程序的所有其他功能的可執行文件,但沒有問題。沒有顯示可見的錯誤,並且在編譯之前應用程序正常工作。

謝謝你的幫助。

+0

[mcve]會很有用。例如,整個setup.py會告訴我'data_files = matplotlib.get_py2exe_datafiles()'是否出現在[answer](http://stackoverflow.com/a/11062854/5781248) –

+0

@JJHakala,我已經更新了安裝腳本。我確實使用data_files = matplotlib.get_py2exe_datafiles() –

回答

0

我的故障排除發現numpy.core是我的問題的罪魁禍首。我重新安裝numpy,現在可執行文件正常運行。