首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImportError:无法导入名称QtGui

ImportError:无法导入名称QtGui
EN

Stack Overflow用户
提问于 2014-12-10 11:19:01
回答 1查看 5.7K关注 0票数 0

我在我的linux 32位计算机上安装了Qt5.3(32位)安装程序。

  • 然后,我安装了最后一个版本的sip -sip 4.16.4
  • 然后我安装了来自http://www.riverbankcomputing.co.uk/software/pyqt/download的Pyqt-PyQt-x11-GPL-4.11.3.tar.gz的最后一个版本。
  • 在我的计算机中安装了python2.7和python3.2版本。当我尝试用python2.7安装时,我犯了一些错误。然后我尝试用pthon3.2安装它。没有发生错误,我使用python3.2正确地安装了它
  • 我同时安装了py2.7-dev和py3.2-dev包。
  • gdb,gcc,g++,python2.7,python3.2,编译基本都安装在我的电脑里.
  • 我从软件中心安装了Qt设计器。
  • 然后我按照教程的说明放置了一个简单的按钮:http://www.youtube.com/watch?v=GLqrzLIIW2E
  • 然后,我保存了example.ui
  • 然后,在终端中给出以下命令: pyuic4 example.ui > example.py。它将.ui文件转换为.py文件。然后,我做了必要的修改,告诉在youtube教程,我告诉了上面。

- -当我使用python3.2运行python3.2文件的最终版本时,它会给出错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "outFile_ui.py", line 12, in <module>
    from PyQt4 import QtCore, QtGui
ImportError: cannot import name QtGui

-为什么我要接受这个错误?我认为问题是在不匹配的版本,或安装等。但我安装了一次又一次。不幸的是什么都没有改变。我在网上搜索了所有关于这个问题的信息。同样的问题也存在,但是没有一个对我有用。

  • 如果您想看到我在终端上运行的python文件,它是: 从PyQt4导入QtCore,QtGui导入sys try:_fromUtf8 = QtCore.QString.fromUtf8除了AttributeError: def _fromUtf8(s):返回s try:_encoding = QtGui.QApplication.UnicodeUTF8 def _translate(上下文、文本、disambig):返回QtGui.QApplication.translate(上下文、文本、disambig、_encoding除外),除了AttributeError: def _translate(上下文、文本、disambig):返回QtGui.QApplication.translate(上下文、文本、类Ui_Form(QtGui.QWidget):def __init__(self):QtGui.QWidget.__init__(self) self.setupUi(self) def setupUi(self,Form):Form.setObjectName(_fromUtf8(“Form”) Form.resize(400,( self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.printHam_btn = QtGui.QPushButton(Form) self.printHam_btn.setObjectName(_fromUtf8("printHam_btn")) self.verticalLayout.addWidget(self.printHam_btn)self.horizontalLayout.addLayout(self.verticalLayout) self.retranslateUi(表单)QtCore.QMetaObject.connectSlotsByName(表单) def retranslateUi(self,(表格):self.printHam_btn.clicked.connect(self.printHam) def printHam(自我):打印("Ham!")如果__name__ ==‘__main_’:app = QtGui.QApplication(sys.argv) ex = Ui_Form() ex.show() sys.exit(app.exec_())
EN

回答 1

Stack Overflow用户

发布于 2015-01-12 23:56:39

将.ui转换为.py代码后,需要添加一个主函数。主功能适当添加后,运行良好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27399692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档