Spyder: PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class. iPython

Created on 2 Oct 2015  路  18Comments  路  Source: spyder-ide/spyder

Spyder 2.3.6, Python 3.5.0 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Linux
IPython >=1.0 : 4.0.0 (OK)
jedi >=0.8.1 : 0.9.0 (OK)
matplotlib >=1.0: 1.4.3 (OK)
pandas >=0.13.1 : 0.16.2 (OK)
pep8 >=0.6 : 1.6.2 (OK)
psutil >=0.3 : 3.2.1 (OK)
pyflakes >=0.6.0: 1.0.0 (OK)
pygments >=1.6 : 2.0.2 (OK)
pylint >=0.25 : 1.5.0 (OK)
qtconsole >=4.0 : 4.0.1 (OK)
rope >=0.9.2 : 0.9.4-1 (OK)
sphinx >=0.6.6 : 1.3.1 (OK)
sympy >=0.7.3 : 0.7.7.dev (OK)
zmq >=2.1.11 : 14.7.0 (OK)

Running this script in an iPython console:

import matplotlib.pyplot

Returns lots of text and finally:
RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class

The same does not happen in normal Python console.

I believe it has something to do with some Startup setting for the iPython console in Spyder but I don't enough knowledge to find out the specific point.

Importing just matplotlib does not cause this error. Is it something wrong with the pyplot module or with iPython console configuration?

Most helpful comment

The t int Qt should be lowercase, I don't know if it matters.

I don't know why it has no effect, this is a common fix (see for example https://bitbucket.org/jpcgt/flatcam/issues/128/arch-linux-with-qt5-getting-the)

All 18 comments

What is your Spyder version?

Spyder 2.3.6

Sorry, forgot that.

I can't reproduce this error, sorry. It's (most probably) a problem with your installation.

I removed Spyder completely and installed it again and the problem persists. Also, after a google search, it seems some other people had this problem as well.

Very similar environment:
https://stackoverflow.com/questions/30697089/how-to-force-pyqt5-use-for-qobject-class

The person who posted this later commented: "I finally found the origin of the problem. I was using Spyder for developping and testing my code; and that IDE uses PyQt4, which was, consequently, also loaded." and also: "I tried to import QObject before anything else, but I still have the same error. But I just tried something else, and I realized that the problem came from iPython".

iPython is packaged together with Spyder for my GNU/Linux distro (Manjaro).

I'm sorry if this has little or nothing to do with Spyder, but which module should I reinstall in order to try fixing this issue?

The problem is that you're using both PyQt4 (in spyder) and PyQt5 (in matplotlib). One solution is to force matplotlib to sue Qt4. If I remember well, it's something like:

import matplotlib
matplotlib.use("Q4Agg")

Yes, I also think what @Nodd says is the error you're facing. You probably are setting your matplotlib backend in your matplotlibrc configuration file.

Since this is not a Spyder issue per se, I'm closing it. But feel free to keep posting comments if you want more advice from us :-)

@ccordoba12 I had this problem too, it happens with no modification in matplotlibrc . When both PyQt5 and PyQt4 are installed, matplotlib uses PyQt5 by default even if PyQt4 is already used. Maybe we should add a workaround in spyder, or just wait for spyder v3.0 which will use PyQt5 too.

Thanks for the info guys and for the possibility to discuss the issue.

Sadly, the problem persists.
A file with these three lines:

import matplotlib as mpl
mpl.use("QT4Agg")
import matplotlib.pyplot as plt

produces the same error. Normal python console works fine though.
I reinstalled both Spyder and matplotlib without solving the problem.

The t int Qt should be lowercase, I don't know if it matters.

I don't know why it has no effect, this is a common fix (see for example https://bitbucket.org/jpcgt/flatcam/issues/128/arch-linux-with-qt5-getting-the)

Very strange... The said solution:

from PyQt4 import QtGui, QtCore
import matplotlib #new line
matplotlib.use("Qt4Agg") #new line

Still outputs the error for me. Again, this never happens with simple Python console. Just upgraded to newest versions of all packages (python 3.5.0, etc...) and, as expected, no fix.

Thanks for the attention and the help folks. I guess I will just use normal console until Spyder (or iPython?) adopts Qt5...

If you feel adventurous, you can use the development version of spyder, which works with Qt5. I use it every day at work so it's still quite stable.

Hello there, especially khalismur. I am getting the exact same error message.

Did you ever find a solution to this problem? Spyder3 v3 is still not released yet so it's not really an option for me. I don't understand why this wouldn't work with Spyder 2.3.8.

Really, I just need Spyder to use the PyQt4 runtimes and then use PyQt5 for my development.

I think that on the stable version of spyder you can't run a program that uses PyQt5. I'm not sure why exactly, maybe because of some hooks used to integrate the executions into spyder (like breakpoints or variable explorer for example).
Even on spyder v3, I have to switch the configuration option I pointed to earlier because some program use PyQt4 and others PyQt5.

Thanks for your quick reply Nodd. Looks like I'll have to use Spyder v3 beta for now. PyQt4 is just too old!

Someone told me finally how to fix the problem. In the run settings select "use an external system console". Works fine! I am successfully using Spyder3 v2.3.8 with PyQt5!

Oh right, I didn't think about that. That's great !

Just a note: the problem is present even when no matplotlib is used. I started Spyder 2 and wrote a small PyQt5 only (no other Qt-related modules included). Upon running I got that same error. I find the whole Spyder and Spyder2 separation quite problematic. Basically you have to switch to a different version of Spyder every time you want to use a different version of PyQt (and Python respectively). Spyder 2 should support both Python 2.x and 3.x plus PyQt4 and PyQt5 without the need to switch back to Spyder (if all this is done then Spyder will basically become obsolete). In terms of user experience if this is done Spyder will improve greatly omho.

image
it seems to work for me: comment the original two lines(above), and add two new lines(below), it has no error.

Was this page helpful?
0 / 5 - 0 ratings