RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1177232
Accepted
Mswork6
Mswork6
Asked:2020-09-12 04:22:27 +0000 UTC2020-09-12 04:22:27 +0000 UTC 2020-09-12 04:22:27 +0000 UTC

文件转换为exe后打不开

  • 772

将.py文件转换为.exe使用图像的文件后,在启动时会出错:

ModuleNotFoundError:没有名为“images_rc”的模块

(带有图像的文件),尽管该文件images_rc位于同一目录中。如何解决这个问题呢?

更新:

成语理论.py

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_IdiomsTheory(object):
    def setupUi(self, IdiomsTheory):
        IdiomsTheory.setObjectName("IdiomsTheory")
        IdiomsTheory.resize(1100, 649)
        IdiomsTheory.setStyleSheet("background-color: #d580ff")
        self.centralwidget = QtWidgets.QWidget(IdiomsTheory)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(9, 0, 1081, 58))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(12)
        self.label.setFont(font)
        self.label.setStyleSheet("color: #ffffb3")
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.label_2 = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(12)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("color: #aa00ff")
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
        self.label_2.setObjectName("label_2")
        self.verticalLayout.addWidget(self.label_2)
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(30, 90, 621, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(13)
        self.label_3.setFont(font)
        self.label_3.setAlignment(QtCore.Qt.AlignCenter)
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(30, 140, 301, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_4.setFont(font)
        self.label_4.setWordWrap(True)
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(30, 230, 301, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_5.setFont(font)
        self.label_5.setWordWrap(True)
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(30, 320, 301, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_6.setFont(font)
        self.label_6.setWordWrap(True)
        self.label_6.setObjectName("label_6")
        self.label_7 = QtWidgets.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(30, 410, 301, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_7.setFont(font)
        self.label_7.setWordWrap(True)
        self.label_7.setObjectName("label_7")
        self.label_8 = QtWidgets.QLabel(self.centralwidget)
        self.label_8.setGeometry(QtCore.QRect(350, 140, 301, 101))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_8.setFont(font)
        self.label_8.setWordWrap(True)
        self.label_8.setObjectName("label_8")
        self.label_9 = QtWidgets.QLabel(self.centralwidget)
        self.label_9.setGeometry(QtCore.QRect(350, 260, 301, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_9.setFont(font)
        self.label_9.setWordWrap(True)
        self.label_9.setObjectName("label_9")
        self.label_10 = QtWidgets.QLabel(self.centralwidget)
        self.label_10.setGeometry(QtCore.QRect(350, 360, 301, 111))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(11)
        self.label_10.setFont(font)
        self.label_10.setWordWrap(True)
        self.label_10.setObjectName("label_10")
        self.label_12 = QtWidgets.QLabel(self.centralwidget)
        self.label_12.setGeometry(QtCore.QRect(670, 140, 411, 341))
        self.label_12.setStyleSheet("")
        self.label_12.setText("")
        self.label_12.setTextFormat(QtCore.Qt.AutoText)
        self.label_12.setPixmap(QtGui.QPixmap(":/page1/Images/Unit 4/4a/IdiomsImages/4a1.png"))
        self.label_12.setScaledContents(True)
        self.label_12.setObjectName("label_12")
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(10, 580, 356, 23))
        self.pushButton_4.setStyleSheet("QPushButton {background-color: #f2f2f2;\n"
"    border: 1px solid black;\n"
"    border-radius: 10\n"
" }\n"
"\n"
"QPushButton:pressed  { \n"
"    background-color: #cccccc;\n"
" }\n"
"")
        self.pushButton_4.setObjectName("pushButton_4")
        self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_5.setGeometry(QtCore.QRect(370, 580, 355, 23))
        self.pushButton_5.setStyleSheet("QPushButton {background-color: #f2f2f2;\n"
"    border: 1px solid black;\n"
"    border-radius: 10\n"
" }\n"
"\n"
"QPushButton:pressed  { \n"
"    background-color: #cccccc;\n"
" }\n"
"")
        self.pushButton_5.setObjectName("pushButton_5")
        self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_6.setGeometry(QtCore.QRect(730, 580, 356, 23))
        self.pushButton_6.setStyleSheet("QPushButton {background-color: #f2f2f2;\n"
"    border: 1px solid black;\n"
"    border-radius: 10\n"
" }\n"
"\n"
"QPushButton:pressed  { \n"
"    background-color: #cccccc;\n"
" }\n"
"")
        self.pushButton_6.setObjectName("pushButton_6")
        IdiomsTheory.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(IdiomsTheory)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1100, 21))
        self.menubar.setObjectName("menubar")
        IdiomsTheory.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(IdiomsTheory)
        self.statusbar.setObjectName("statusbar")
        IdiomsTheory.setStatusBar(self.statusbar)

        self.retranslateUi(IdiomsTheory)
        QtCore.QMetaObject.connectSlotsByName(IdiomsTheory)

    def retranslateUi(self, IdiomsTheory):
        _translate = QtCore.QCoreApplication.translate
        IdiomsTheory.setWindowTitle(_translate("IdiomsTheory", "Idioms Theory"))
        self.label.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" font-size:16pt; font-weight:600;\">Unit 4a</span></p></body></html>"))
        self.label_2.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" font-size:16pt; font-weight:600;\">Come rain or shine!</span></p></body></html>"))
        self.label_3.setText(_translate("IdiomsTheory", "Idioms"))
        self.label_4.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">Under the weather</span><span style=\" text-decoration: underline;\"> - slightly unwell</span></p><p><span style=\" font-style:italic;\">Example: Yumi is feeling under the weather, so she won\'t be going to work today.</span></p></body></html>"))
        self.label_5.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">On cloud nine</span><span style=\" text-decoration: underline;\"> - extremely happy</span></p><p><span style=\" font-style:italic;\">Example: Mo is on cloud nine - his wife is pregnant</span></p></body></html>"))
        self.label_6.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">A breeze</span><span style=\" text-decoration: underline;\"> - very easy</span></p><p><span style=\" font-style:italic;\">Example: Studying English is a breeze. I\'m progressin so quickly</span></p></body></html>"))
        self.label_7.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">Rain cats and dogs</span><span style=\" text-decoration: underline;\"> - rain very hard </span></p><p><span style=\" font-style:italic;\">Example: I was going to go shopping, but it suddenly started raining cats and dogs, so I stayed home</span></p></body></html>"))
        self.label_8.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">Save up for a rainy day</span><span style=\" text-decoration: underline;\"> - put some money aside for whenever it may be needed</span></p><p><span style=\" font-style:italic;\">Example: Once you have the basic home comforts, it\'s importnat to save up for a rainy day</span></p></body></html>"))
        self.label_9.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">Storm in a teacup</span><span style=\" text-decoration: underline;\"> - small problem that has been blown out of proportion</span></p><p><span style=\" font-style:italic;\">Example: In my opininon, the whole thing is just a storm in a teacup </span></p></body></html>"))
        self.label_10.setText(_translate("IdiomsTheory", "<html><head/><body><p><span style=\" text-decoration: underline; color:#55007f;\">Head in the clouds</span><span style=\" text-decoration: underline;\"> - not being realistic or daydreaming</span></p><p><span style=\" font-style:italic;\">Example: He can\'t continue going around with his head in the clouds; he must be more realistic about his problems</span></p></body></html>"))
        self.pushButton_4.setText(_translate("IdiomsTheory", "Go to previous page"))
        self.pushButton_5.setText(_translate("IdiomsTheory", "Go to unit contents"))
        self.pushButton_6.setText(_translate("IdiomsTheory", "Go to next page"))
import images_rc


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    IdiomsTheory = QtWidgets.QMainWindow()
    ui = Ui_IdiomsTheory()
    ui.setupUi(IdiomsTheory)
    IdiomsTheory.show()
    sys.exit(app.exec_())

转换字符串:

pyinstaller -F -w IdiomsTheory.py

图片.qrc

<RCC>
  <qresource prefix="page1">
    <file>Images/Unit 4/4a/IdiomsImages/1_1.png</file>
    <file>Images/Unit 4/4a/IdiomsImages/1_2.png</file>
    <file>Images/Unit 4/4a/IdiomsImages/1_3.png</file>
    <file>Images/Unit 4/4a/IdiomsImages/4a1.png</file>
    <file>Images/Unit 4/4a/IdiomsImages/4a2.png</file>
    <file>Images/Unit 4/4a/IdiomsImages/weather1_0.png</file>
  </qresource>
  <qresource prefix="page2">
    <file>Images/Unit 4/4a/VocabularyImages/1.png</file>
    <file>Images/Unit 4/4a/VocabularyImages/2.png</file>
  </qresource>
  <qresource prefix="page3"/>
</RCC>
python
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    S. Nick
    2020-09-12T05:50:57Z2020-09-12T05:50:57Z

    我像你一样做了所有事情,只是在模块中我IdiomsTheory.py用 替换了名称IdiomsTheory,w因为 我不喜欢它们(我没有尝试过你的)。

    成语理论.py

    ...
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        w = QtWidgets.QMainWindow()                       # w
        ui = Ui_IdiomsTheory()
        ui.setupUi(w)                                     # w
        w.show()                                          # w 
        sys.exit(app.exec_())
    

    图片.qrc

    <RCC>
      <qresource prefix="page1">
        <file>Images/Unit 4/4a/IdiomsImages/4a1.png</file>
      </qresource>
    </RCC>
    
    • 更远

      pyrcc5 images.qrc -o images_rc.py

    • 更远

      pyinstaller -F -w IdiomsTheory.py

    在此处输入图像描述

    在此处输入图像描述

    一切正常!

    • 1

相关问题

  • 是否可以以某种方式自定义 QTabWidget?

  • telebot.anihelper.ApiException 错误

  • Python。检查一个数字是否是 3 的幂。输出 无

  • 解析多个响应

  • 交换两个数组的元素,以便它们的新内容也反转

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何从列表中打印最大元素(str 类型)的长度?

    • 2 个回答
  • Marko Smith

    如何在 PyQT5 中清除 QFrame 的内容

    • 1 个回答
  • Marko Smith

    如何将具有特定字符的字符串拆分为两个不同的列表?

    • 2 个回答
  • Marko Smith

    导航栏活动元素

    • 1 个回答
  • Marko Smith

    是否可以将文本放入数组中?[关闭]

    • 1 个回答
  • Marko Smith

    如何一次用多个分隔符拆分字符串?

    • 1 个回答
  • Marko Smith

    如何通过 ClassPath 创建 InputStream?

    • 2 个回答
  • Marko Smith

    在一个查询中连接多个表

    • 1 个回答
  • Marko Smith

    对列表列表中的所有值求和

    • 3 个回答
  • Marko Smith

    如何对齐 string.Format 中的列?

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5