简体   繁体   English

导入错误:无法导入名称 pyqtSignal?

[英]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.问题背景:这是我之前的 PyQt 项目,我正在研究并尝试启动 GUI。 I have set an Anaconda Environment with Python 2.7 and used PyQt4.我已经使用 Python 2.7 设置了一个 Anaconda 环境并使用了 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.即使在尽我所能尝试设置环境和其他方面之后,我也无法确定为什么仍然会弹出此错误。在 Mac 上尝试过,即使在 Ubuntu 上也会出现类似错误。 Does anyone have an idea how to tackle this?有谁知道如何解决这个问题?

You're using qtpy rather than PyQt4 directly.您正在直接使用qtpy而不是PyQt4 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.根据Don't delete QtCore.{pyqtSignal,pyqtSlot,pyqtProperty} · Issue #76 · spyder-ide/qtpy · GitHub ,他们故意放弃了PyQt特定的名称,如pyqtSignal ,而是在导入时将它们重命名为Signal等通用名称以保持一致性. They comment that these names follow Qt5 's naming scheme.他们评论说这些名称遵循Qt5的命名方案。

So you should just所以你应该只是

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

and rename all pyqtSignal to Signal elsewhere in your code.并将所有pyqtSignal重命名为代码中其他pyqtSignalSignal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM