Search code examples
pythonpython-2.7pyqt4qtpy

ImportError: cannot import name pyqtSignal?


Background on the question: This is a previous PyQt project I am working on and trying to start the GUI. I have set an Anaconda Environment with Python 2.7 and used PyQt4. The Error is :-

File "gui/gui.py", line 26, in <module> from qtpy.QtCore import (Qt, QFileSystemWatcher, QSettings, pyqtSignal) ImportError: cannot import name pyqtSignal

Code :-

enter #import qt
from qtpy import QtCore, QtWidgets, QtGui, PYQT4 #changed from PYQT5
from qtpy.QtCore import (Qt, QFileSystemWatcher, QSettings, pyqtSignal)

Even after trying to setup the environment and other aspects to the best of my ability, I am unable to pinpoint why this error still pops up.Tried on Mac, it errors out similarly even on Ubuntu. Does anyone have an idea how to tackle this?


Solution

  • You're using qtpy rather than PyQt4 directly. According to Don't delete QtCore.{pyqtSignal,pyqtSlot,pyqtProperty} · Issue #76 · spyder-ide/qtpy · GitHub, they deliberately ditched PyQt-specific names like pyqtSignal and instead rename them upon import to generic names like Signal for uniformity. They comment that these names follow Qt5's naming scheme.

    So you should just

    from qtpy.QtCore import Qt, QFileSystemWatcher, QSettings, Signal
    

    and rename all pyqtSignal to Signal elsewhere in your code.