Search code examples
ipythontraitsenthought

Traits import in IPython notebook or qtconsole


I have troubles while importing a Python module that imports this:

from traits.api import HasTraits, Float, CFloat, Range, Property
from traitsui.api import View, Item, UItem, Tabbed, HGroup, VGroup, Group
from chaco.api import ArrayPlotData, Plot
from enable.component_editor import ComponentEditor
from numpy import deg2rad, pi, cos, sqrt

# physical constants
from scipy.constants import h,c

on my Lion Macbook Pro. The python rocket comes up in the dock, but just won't ever stop jumping up and down. This happens both in iPython's notebook with activated pylab mode and the qtconsole. In a terminal with ipython --pylab it works fine. Does it maybe have something to do with backends? I think my default is wx.


Solution

  • Yes, IPython needs to be informed when you are using a GUI eventloop (wx/qt/gtk/etc.), so it can integrate the inputhook needed for talking to the terminal into that eventloop. ETS/chaco does use such a backend, so to use these interactively in IPython, you must enable eventloop integration. ipython --pylab implies this integration with the eventloop associated with the default matplotlib backend, as well as various namespace initializations. But you can just integrate IPython with the eventloop by doing --gui wx (assuming wx, use qt, tk, etc. as appropriate). You can even do this after starting IPython by activating the backend with %gui wx.