Jer*_*nin 5 python pyqt4 qobject python-3.x pyqt5
我正在使用Python 3和PyQt5开发一个小型图形应用程序.在我使用的第一台计算机上,只安装了PyQt5,我的代码中的所有内容都很好.但是当我想在我的其他笔记本电脑上运行我的代码时,安装了PyQt4和PyQt5,我收到以下错误:
RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class
Run Code Online (Sandbox Code Playgroud)
Python解释器将错误定位在从主文件调用的文件"ViewWindow.py"中.
因为我在这台笔记本电脑上有PyQt4和PyQt5,并且因为我无法卸载PyQt4(这太简单了......),我想知道是否有可能强制使用PyQt5.QtCore或其他东西来避免这个问题.我在这台笔记本电脑上的配置:Debian 8,Python3.4,PyQt4和5(没有特殊配置,从Debian repos安装),IDE = Spyder.
我把我的文件有第一线main.py和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):
Run Code Online (Sandbox Code Playgroud)
有人知道如何运行此代码吗?
谢谢,
杰瑞M.
编辑:我试图运行该脚本强制使用Python3,它工作...似乎问题来自iPython3.谢谢你的帮助.
RuntimeError带有消息的A
和模块
PyQt5.QtCore都PyQt4.QtCore包装QObject类
当您尝试导入时会引发该错误PyQt5.QtCore,而PyQt4.QtCore之前已经导入过。
此错误是在用于连接到 Qt 的SIP中引发的。就像它所说的那样,只允许有一个模块声称包装QObject。因此,该错误只是告诉您,您正在同时使用 PyQt4 和 PyQt5。
因此,您需要找到加载 PyQt4 的模块,将其配置为使用 PyQt5。或者,您可以尝试将其放在from PyQt5.QtCore import QObject任何其他导入之前,并希望通常从 PyQt4 导入的模块具有适应性,并且能够使用 PyQt5 作为后备。