ImportError: No module named 'resource_rc'
Solution 1
You should have a file called resource.qrc
, this must be converted to .py
, this or you can do it by executing:
pyrcc5 resource.qrc -o resource_rc.py
Solution 2
When you compile a .ui file, it uses the resources_rc.py (which must be compiled as well) to store its resources. For example, if you open the qrc file, you will see the items it has stored. If your ui uses anything from the resources_rc.py, file you will get the error you saw.
Solution 3
with python3, i use this:
pyrcc5 file.qrc -o file.py
https://i.stack.imgur.com/UhvOS.png
Solution 4
import resource_rc
you may fix this with --from-imports option .
pyuic4 -h
--from-imports generate imports relative to '.'
Example:
pyuic4 --from-imports -w -o aboutBA.py aboutBA.ui
![QueN](https://i.stack.imgur.com/oIr1m.png?s=256&g=1)
QueN
Updated on December 07, 2021Comments
-
QueN over 2 years
I made a simple program with PyQt GUI, and compiled '.ui' file.
# Form implementation generated from reading ui file 'main.ui' # # Created by: PyQt5 UI code generator 5.6 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.setEnabled(True) MainWindow.resize(441, 255) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) MainWindow.setAutoFillBackground(False) MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded) self.frame = QtWidgets.QWidget(MainWindow) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setObjectName("frame") self.tab = QtWidgets.QTabWidget(self.frame) self.tab.setGeometry(QtCore.QRect(10, 10, 421, 201)) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.tab.sizePolicy().hasHeightForWidth()) self.tab.setSizePolicy(sizePolicy) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.tab.setFont(font) self.tab.setTabShape(QtWidgets.QTabWidget.Triangular) self.tab.setMovable(False) self.tab.setTabBarAutoHide(False) self.tab.setObjectName("tab") self.tabOption = QtWidgets.QWidget() self.tabOption.setObjectName("tabOption") self.profileList = QtWidgets.QComboBox(self.tabOption) self.profileList.setGeometry(QtCore.QRect(60, 10, 121, 20)) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.profileList.setFont(font) self.profileList.setObjectName("profileList") self.ramInput = QtWidgets.QLineEdit(self.tabOption) self.ramInput.setGeometry(QtCore.QRect(50, 40, 81, 20)) self.ramInput.setObjectName("ramInput") self.ramLabel = QtWidgets.QLabel(self.tabOption) self.ramLabel.setGeometry(QtCore.QRect(10, 40, 31, 21)) font = QtGui.QFont() font.setFamily("나눔바른고딕 UltraLight") font.setPointSize(10) self.ramLabel.setFont(font) self.ramLabel.setObjectName("ramLabel") self.ramUnit = QtWidgets.QComboBox(self.tabOption) self.ramUnit.setGeometry(QtCore.QRect(140, 40, 41, 22)) self.ramUnit.setObjectName("ramUnit") self.ramUnit.addItem("") self.ramUnit.addItem("") self.ramUnit.addItem("") self.profileLabel = QtWidgets.QLabel(self.tabOption) self.profileLabel.setGeometry(QtCore.QRect(10, 10, 41, 21)) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.profileLabel.setFont(font) self.profileLabel.setObjectName("profileLabel") self.logo = QtWidgets.QLabel(self.tabOption) self.logo.setGeometry(QtCore.QRect(180, 10, 231, 151)) self.logo.setStyleSheet("image: url(:/logo/logo.png);") self.logo.setText("") self.logo.setObjectName("logo") self.javaLabel = QtWidgets.QLabel(self.tabOption) self.javaLabel.setGeometry(QtCore.QRect(10, 70, 61, 21)) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.javaLabel.setFont(font) self.javaLabel.setObjectName("javaLabel") self.javaInput = QtWidgets.QLineEdit(self.tabOption) self.javaInput.setGeometry(QtCore.QRect(80, 70, 101, 20)) self.javaInput.setObjectName("javaInput") self.javaLabelOptinal = QtWidgets.QLabel(self.tabOption) self.javaLabelOptinal.setGeometry(QtCore.QRect(10, 80, 61, 21)) font = QtGui.QFont() font.setFamily("나눔바른고딕 UltraLight") font.setPointSize(6) self.javaLabelOptinal.setFont(font) self.javaLabelOptinal.setObjectName("javaLabelOptinal") self.launch = QtWidgets.QCommandLinkButton(self.tabOption) self.launch.setGeometry(QtCore.QRect(10, 110, 171, 41)) self.launch.setObjectName("launch") self.tab.addTab(self.tabOption, "") self.tabConsole = QtWidgets.QWidget() self.tabConsole.setObjectName("tabConsole") self.console = QtWidgets.QTextBrowser(self.tabConsole) self.console.setGeometry(QtCore.QRect(10, 10, 391, 131)) self.console.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.console.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.console.setPlaceholderText("") self.console.setObjectName("console") self.commandInput = QtWidgets.QLineEdit(self.tabConsole) self.commandInput.setGeometry(QtCore.QRect(10, 150, 391, 20)) self.commandInput.setText("") self.commandInput.setObjectName("commandInput") self.tab.addTab(self.tabConsole, "") MainWindow.setCentralWidget(self.frame) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setEnabled(True) self.menubar.setGeometry(QtCore.QRect(0, 0, 441, 21)) font = QtGui.QFont() font.setFamily("나눔바른고딕 UltraLight") font.setPointSize(10) self.menubar.setFont(font) self.menubar.setToolTip("Settings about profiles") self.menubar.setObjectName("menubar") self.menuProfiles = QtWidgets.QMenu(self.menubar) self.menuProfiles.setObjectName("menuProfiles") self.menuSettings = QtWidgets.QMenu(self.menubar) self.menuSettings.setObjectName("menuSettings") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) font = QtGui.QFont() font.setFamily("") font.setPointSize(10) self.statusbar.setFont(font) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionCreate_new_profile = QtWidgets.QAction(MainWindow) font = QtGui.QFont() font.setFamily("나눔바른고딕 UltraLight") font.setPointSize(10) self.actionCreate_new_profile.setFont(font) self.actionCreate_new_profile.setObjectName("actionCreate_new_profile") self.actionDelete_a_profile = QtWidgets.QAction(MainWindow) font = QtGui.QFont() font.setFamily("나눔바른고딕 UltraLight") font.setPointSize(10) self.actionDelete_a_profile.setFont(font) self.actionDelete_a_profile.setObjectName("actionDelete_a_profile") self.actionProfile_Settings = QtWidgets.QAction(MainWindow) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.actionProfile_Settings.setFont(font) self.actionProfile_Settings.setObjectName("actionProfile_Settings") self.actionGlobal_settings = QtWidgets.QAction(MainWindow) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.actionGlobal_settings.setFont(font) self.actionGlobal_settings.setObjectName("actionGlobal_settings") self.actionAuto_completes = QtWidgets.QAction(MainWindow) font = QtGui.QFont() font.setFamily("UltraLight") font.setPointSize(10) self.actionAuto_completes.setFont(font) self.actionAuto_completes.setObjectName("actionAuto_completes") self.menuProfiles.addAction(self.actionCreate_new_profile) self.menuProfiles.addAction(self.actionDelete_a_profile) self.menuSettings.addAction(self.actionProfile_Settings) self.menuSettings.addAction(self.actionGlobal_settings) self.menuSettings.addSeparator() self.menuSettings.addAction(self.actionAuto_completes) self.menubar.addAction(self.menuProfiles.menuAction()) self.menubar.addAction(self.menuSettings.menuAction()) self.retranslateUi(MainWindow) self.tab.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.ramLabel.setText(_translate("MainWindow", "RAM:")) self.ramUnit.setItemText(0, _translate("MainWindow", "GB")) self.ramUnit.setItemText(1, _translate("MainWindow", "MB")) self.ramUnit.setItemText(2, _translate("MainWindow", "KB")) self.profileLabel.setText(_translate("MainWindow", "Profile:")) self.javaLabel.setText(_translate("MainWindow", "Java Path:")) self.javaLabelOptinal.setText(_translate("MainWindow", "(Optinal)")) self.launch.setText(_translate("MainWindow", "Launch Bukkit!")) self.tab.setTabText(self.tab.indexOf(self.tabOption), _translate("MainWindow", "Launch Options")) self.tab.setTabText(self.tab.indexOf(self.tabConsole), _translate("MainWindow", "Console")) self.menuProfiles.setTitle(_translate("MainWindow", "Profiles")) self.menuSettings.setTitle(_translate("MainWindow", "Settings")) self.actionCreate_new_profile.setText(_translate("MainWindow", "Create a new profile..")) self.actionCreate_new_profile.setShortcut(_translate("MainWindow", "Alt+C")) self.actionDelete_a_profile.setText(_translate("MainWindow", "Delete a profile..")) self.actionDelete_a_profile.setShortcut(_translate("MainWindow", "Alt+D")) self.actionProfile_Settings.setText(_translate("MainWindow", "Profile settings..")) self.actionProfile_Settings.setShortcut(_translate("MainWindow", "Alt+S")) self.actionGlobal_settings.setText(_translate("MainWindow", "Global settings..")) self.actionGlobal_settings.setShortcut(_translate("MainWindow", "Alt+Shift+S")) self.actionAuto_completes.setText(_translate("MainWindow", "Auto completes..")) self.actionAuto_completes.setShortcut(_translate("MainWindow", "Alt+A")) import resource_rc
but it is causing error like below.
ImportError: No module named 'resource_rc'
I tried to find this error in StackOverflow already, but anyone didn't get this error.
I'm using Python 3.5, and PyQt 5.6. (I know PyQt is incompatible with Python 3.5, but I don't have any error except this)
Now, code is working without any problem after I removed last line of codes: 'import resource_rc'
but exactly what is this line doing?
-
QueN over 7 yearsthen it says pyrcc5: File does not exist 'resource.qrc' where does it exist?
-
Jesse Adamson almost 4 yearsnote that mine is resources with a 's' on both files. I am now getting "No resources in resource description" which may be because my file doesn't have much listed, so I'm just using a blank file for now.
-
AlBlue over 3 yearsThis is the same as the accepted answer - it would be better to upvote that one instead of reposting.
-
Pedro Antônio about 2 yearsworks, but my gui.py (just a file for the GUI, not my main file) still not found the generated module (is in same folder). I fixed it commenting the import and using it in my main file. So it works and my resources appear on GUI