The most interesting part is near the bottom, but first what you've asked for. Here is what happens when I import PyQt4:
%gui qt
import PyQt4
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-0c3b8c686717> in <module>()
----> 1 import PyQt4
C:\Anaconda\lib\site-packages\IPython\external\qt_loaders.pyc in load_module(self, fullname)
45 Importing %s disabled by IPython, which has
46 already imported an Incompatible QT Binding: %s
---> 47 """ % (fullname, loaded_api()))
48
49 ID = ImportDenier()
ImportError:
Importing PyQt4 disabled by IPython, which has
already imported an Incompatible QT Binding: pyqtv1
So it seems somewhere Qt API v1 is being set.
There is a snippet of code in there:
import sip
try:
sip.setapi('QDate', 2)
sip.setapi('QDateTime', 2)
sip.setapi('QString', 2)
sip.setapi('QtextStream', 2)
sip.setapi('Qtime', 2)
sip.setapi('QUrl', 2)
sip.setapi('QVariant', 2)
except ValueError, e:
raise RuntimeError('Could not set API version (%s): did you import PyQt4 directly?' % e)
If I start ipython qtconsole normally via: "ipython qtconsole" and then run Cryille's code and then set %gui qt I can run pyqtgraph interactively without hanging. It actually doesn't seem to make any different if I put any tags (--gui, --pylab, etc) on the command line when I run ipython qtconsole
Very interestingly if I start ipython qt console normally, run Cyrille's code and then "import pyqtgraph as pg; pg.image()" the window will hang. If I then run %gui qt the window will unhang and run normally.
Cyrille's suggestions about adding code to the profile "ipython_config.py" files doesn't work, it produces errors, it seems like the API version is getting set to v1 earlier than loading the profile.
I believe this is only a problem for python 2.7 with PyQt4 as it is the last to use the v1 API.
I am stuck on where to go. So I can get pyqtgraph working with the qt console but it is messy and cumbersome. I don't know how to ensure that the v2 API is getting set and I don't know what %gui qt is doing programmtically.