public
Created

If I import matplot and plot a frame with an IPython console window open IPython goes crazy and seg faults my app. I tried configuring my matplotlibrc to use Qt4 as the backend but no joy :(. Not sure how to chase down why IPython is crashing. Im using the 1.0-dev build. and 1.2.1 of matplotlib Any Help?

  • Download Gist
console_ipython.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
import os
from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
 
from IPython.frontend.qt.console.ipython_widget import IPythonWidget
 
from IPython.frontend.qt.kernelmanager import QtKernelManager
from IPython.frontend.qt.inprocess_kernelmanager import QtInProcessKernelManager
from IPython.kernel.zmq.ipkernel import Kernel
from IPython.kernel.inprocess.ipkernel import InProcessKernel
from IPython.lib import guisupport
def print_process_id():
print 'Process ID is:', os.getpid()
def main(arguments={}):
# Print the ID of the main process
#print_process_id()
app = guisupport.get_app_qt4()
# Create an in-process kernel
# >>> print_process_id()
# will print the same process ID as the main process
kernel = InProcessKernel(gui='qt4')
kernel.shell.push(arguments)
kernel_manager = QtInProcessKernelManager(kernel=kernel)
# Uncomment these lines to use a kernel on a separate process
# >>> import os; print os.getpid()
# will give a different process ID
#kernel = Kernel(gui='qt4')
#kernel.shell.push(arguments)
#kernel_manager = QtKernelManager(kernel=kernel)
kernel_manager.start_kernel()
kernel_manager.start_channels()
def stop():
kernel_manager.shutdown_kernel()
kernel_manager.stop_channels()
app.exit()
control = RichIPythonWidget()
#control = IPythonWidget()
control.kernel_manager = kernel_manager
control.exit_requested.connect(stop)
control.show()
#guisupport.start_event_loop_qt4(app)
if __name__ == '__main__':
main()
main_window.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
import sys
 
import console_ipython
from PyQt4 import QtGui
 
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt
import random
 
from PyQt4.QtCore import QT_VERSION_STR
from PyQt4.pyqtconfig import Configuration
 
print("Qt version:", QT_VERSION_STR)
cfg = Configuration()
print("SIP version:", cfg.sip_version_str)
print("PyQt version:", cfg.pyqt_version_str)
 
 
class Window(QtGui.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
 
# a figure instance to plot on
self.figure = plt.figure()
 
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
 
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
 
# Just some button connected to `plot` method
self.button = QtGui.QPushButton('Plot')
self.button.clicked.connect(self.plot)
 
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
console_ipython.main()
def plot(self):
console_ipython.main()
''' plot some random stuff '''
# random data
data = [random.random() for i in range(10)]
 
# create an axis
ax = self.figure.add_subplot(111)
 
# discards the old graph
ax.hold(False)
 
# plot data
ax.plot(data, '*-')
 
# refresh canvas
self.canvas.draw()
 
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
 
main = Window()
main.show()
 
sys.exit(app.exec_())

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.