带有 MatplotLib 的 EXE 崩溃
EXE with MatplotLib Crashes
我正在使用 Python 3.4 和 PyQt4 开发一个应用程序,LiClipse 作为 IDE 并且在我编译程序后绘制图表时出现问题关闭整个程序没有错误成一个可执行文件。我已经指出了问题区域并且知道调用 matplotlib.figure.Figure() 是崩溃的罪魁祸首,但我不知道从这里去哪里。
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
)
我能够在可执行文件中 运行 我的应用程序的所有其他功能,但没有问题。没有显示可见错误,并且应用程序在编译之前工作正常。
感谢您的帮助。
我的故障排除发现 numpy.core 是我的问题的罪魁祸首。我重新安装了 numpy,可执行文件现在可以正常运行了。
我正在使用 Python 3.4 和 PyQt4 开发一个应用程序,LiClipse 作为 IDE 并且在我编译程序后绘制图表时出现问题关闭整个程序没有错误成一个可执行文件。我已经指出了问题区域并且知道调用 matplotlib.figure.Figure() 是崩溃的罪魁祸首,但我不知道从这里去哪里。
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
)
我能够在可执行文件中 运行 我的应用程序的所有其他功能,但没有问题。没有显示可见错误,并且应用程序在编译之前工作正常。
感谢您的帮助。
我的故障排除发现 numpy.core 是我的问题的罪魁祸首。我重新安装了 numpy,可执行文件现在可以正常运行了。