How to force PyQt5 to use the QObject class?

I am developing a small graphical application using Python 3 and PyQt5. On the first computer, I use where only PyQt5 is installed, everything in my code is fine. But when I want to run my code on another laptop where PyQt4 and PyQt5 are installed, I get the following error:

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

The Python interpreter detects an error in the file "ViewWindow.py", is called from the main file.

Since I have both PyQt4 and PyQt5 on this laptop, and because I cannot remove PyQt4 (that would be too easy ...), I wonder if it is possible to force the use of PyQt5.QtCore or something else to avoid this problem. My configuration on this laptop: Debian 8, Python3.4, PyQt4 and 5 (without a special configuration installed from the Debian repositories), IDE = Spyder.

I put the first lines of my files there main.pyand ViewWindow.py.

# main.py
import sys
import sqlite3
import ViewWindow
from DataWindow import DataWindow
from PyQt5.QtCore import QObject # I tried adding this line, but nothing changed...
from PyQt5.QtWidgets import (QApplication,
                         QWidget,
                         QGridLayout,
                         QHBoxLayout,
                         QLabel,
                         QLineEdit,
                         QPushButton,
                         QTextEdit,
                         QVBoxLayout
                         )


class MainWindow(QWidget):
    # Some cool stuff


# ViewWindow.py
import sys
import sqlite3
from PyQt5.QtCore import QObject # same thing than above, adding this line doesn't change the output.
from PyQt5.QtWidgets import (QApplication,
                         QWidget,
                         QGridLayout,
                         QLabel,
                         QPushButton,
                         QVBoxLayout
                         )


class ViewWindow(QWidget):

Does anyone know how to make this code run?

Thank,

Jerry M.


Edit: I tried to run this script forcing to use Python3, and it worked ... It seems that the problem comes from iPython3. Thank you for your help.

+4
source share
1 answer

A RuntimeErrorwith a message

modules PyQt5.QtCoreand PyQt4.QtCorewrap classQObject

occurs when you try to import PyQt5.QtCorewhile it PyQt4.QtCorehas already been imported before.

SIP, Qt. , , QObject. , , PyQt4 PyQt5 .

, , PyQt4, PyQt5. from PyQt5.QtCore import QObject , , PyQt4, PyQt5 .

+2

All Articles