QtConsole/Notebook problems

450 views
Skip to first unread message

john lunzer

unread,
Mar 13, 2015, 12:23:51 PM3/13/15
to pyqt...@googlegroups.com
I am running Anaconda (Python 2.7.8 / Qt 4.8.6 / PyQt 4.10.4). 

When trying to run IPython QtConsole or IPython Notebook (interactive). 

From a simple

import pyqtgraph as pg
pg
.image

My graph windows are hanging (no contents displayed).

I had an Idea to change the gui setting to 'qt' but this produced the following:

%gui qt
import pyqtgraph as pg

---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-2-e5a51b506085> in <module>()
----> 1 import pyqtgraph as pg

C
:\Anaconda\lib\site-packages\pyqtgraph\__init__.py in <module>()
 
11 ## 'Qt' is a local module; it is intended mainly to cover up the differences
 
12 ## between PyQt4 and PySide.
---> 13 from .Qt import QtGui
 
14
 
15 ## not really safe--If we accidentally create another QApplication, the process hangs (and it is very difficult to trace the cause)

C
:\Anaconda\lib\site-packages\pyqtgraph\Qt.py in <module>()
 
30 USE_PYSIDE = True
 
31 except ImportError:
---> 32 raise Exception("PyQtGraph requires either PyQt4 or PySide; neither package could be imported.")
 
33
 
34 if USE_PYSIDE:

Exception: PyQtGraph requires either PyQt4 or PySide; neither package could be imported.


I could use some advice on where to go from here. 

I should note that pyqtgraph works fine from within the ipython console in Spyder or when simply using ipython by itself.

Luke Campagnola

unread,
Mar 13, 2015, 9:18:08 PM3/13/15
to pyqt...@googlegroups.com
Can you try just importing PyQt4 or PySide to see why those are failing?

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/361cdd27-7420-4e44-a682-a8ccf8888745%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

john lunzer

unread,
Mar 14, 2015, 12:14:21 PM3/14/15
to pyqt...@googlegroups.com
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. 

I found a blog post from Cyrille Rossant, here: http://cyrille.rossant.net/making-pyqt4-pyside-and-ipython-work-together/

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.

Luke Campagnola

unread,
Mar 14, 2015, 2:58:28 PM3/14/15
to pyqt...@googlegroups.com
Ok, so my best guess is that ipython is actually importing a different version of pyqt / pyside than pyqtgraph is, since pyqtgraph itself does not attempt to set any particular API versions. On my own machine (linux) everything works as expected although I do need to enter "gui qt" in the ipython qtconsole to make pyqtgraph's plots work. 

Something you could investigate is to inspect sys.modules to see which Qt library is being imported by ipython, and whether this is different from the library that is imported when you run `import PyQt4`. For example, I see the following:

    >>> gui qt

    >>> sys.modules['PyQt4']
    Out[5]: <module 'PyQt4' from '/usr/lib/python2.7/dist-packages/PyQt4/__init__.pyc'>

In this case the package imported by ipython is the same as the one that pyqtgraph would import, so there are no conflicts. If you have further trouble with this, I would recommend asking the ipython and anaconda crowds, since the trouble seems to come from some interaction there..


john lunzer

unread,
Mar 14, 2015, 9:00:50 PM3/14/15
to pyqt...@googlegroups.com
thanks for your responses and guidance. I'll further investigate and report back if there is anything worth reporting!

john lunzer

unread,
Mar 14, 2015, 9:23:27 PM3/14/15
to pyqt...@googlegroups.com
Well, I fixed the issue... updating to ipython to 3.0.0 and using "ipython qtconsole --pylab=qt" to run allows "import pyqtgraph as pg; pg.image()" without any ipython magic.

I'm guessing they finally phased out any API v1 stuff.
Reply all
Reply to author
Forward
0 new messages