[Python-modules-team] Bug#556943: python-matplotlib: Segfaults with Qt4Agg backend

Nicolas Fourcaud-Trocmé nfourcau at olfac.univ-lyon1.fr
Tue Dec 8 14:20:20 UTC 2009


I got a very similar bug recently. I am using a rather big application 
using the Qt4 backend for matplotlib on a debian testing distribution. 
But after a full upgrade last Friday (December the 4th), I suddenly got 
segfault everytime I was trying to display a matplotlib figure. After 
searching around, I noticed that I my application works well everytime I 
have to recreate the "pyc" file used to plot embedded matplotlib figures 
(even by adding a single blank line). But if I do not change the file, I 
got "segfault" on subsequent runs.

I tried to get a minimal program with the same effect but it did not 
completely work since I get segfault on every run... More precisely, I 
get segfault if I start to embed the figure, but do not go until I have 
really plotted something inside. There is the code :

##############################################################

# -*- coding: utf-8 -*-

import sys
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QApplication,QWidget,QVBoxLayout

if __name__ == "__main__":
    app = QApplication(sys.argv)

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
FigureCanvas
from matplotlib.figure import Figure

class MyMplCanvas(FigureCanvas):
    """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, 
etc.)."""
    def __init__(self, parent=None, width=5, height=4, dpi=100 ):
        self.fig = Figure()
        FigureCanvas.__init__(self, self.fig)

class MainWindow(QWidget):
    
#------------------------------------------------------------------------------
    def __init__(self, parent=None) :
        QWidget.__init__(self, parent)
        self.setWindowFlags(Qt.Window)
       
        # Next line only results in segfault
        #~ self.canvas = MyMplCanvas()

        # adding ALL following lines results in correct output
        #~ v2 = QVBoxLayout()
        #~ self.fig = self.canvas.fig
        #~ self.ax1=self.fig.add_subplot(111)
        #~ self.ax1.plot([0,1])
        #~ v2.addWidget(self.canvas)
        #~ self.setLayout(v2)

main=MainWindow()
main.show()

sys.exit(app.exec_())

#################################################

Comparing to the last answer to this bug, my only package differences are :

libc6               2.10.2
libglib2.0       2.22.3
libpango1.0   1.26.1
tcl8.5               8.5.8
tk8.5                8.5.8

I hope this can help.

Regards,

Nicolas Fourcaud-Trocmé






More information about the Python-modules-team mailing list