I'm having trouble importing a resource file. I'm using pyqt4 with monkey studio and I am trying to import a png image. When I run the program I get an import error like
ImportError: No module named icon_rc
I know that I have to compile it using pyrcc4 but I don't understand how to do this can anybody help please. It would be very helpful to have an answer that fully explains how to compile the resource file so I can import it.
Using a QRC file qrc file in your application you first need to compile it to Python. PyQt5 comes with a command line tool to do this, which takes a . qrc file as input and outputs a Python file containing the compiled data. This can then be imported into your app as for any other Python file or module.
DESCRIPTION. pyrcc5 takes a Qt Resource File (. qrc) and converts it into a Python module which can be imported into a PyQt5 application. All files loaded by Qt that are prefixed with a colon will be loaded from the resources rather than the file system.
Open cmd (or terminal on *nix) and run
pyrcc4 -py3 F:\computing\Payrollv22\icon.qrc -o icon_rc.py
It compiled the file successfully and I was able to import the py file into my project and run it with no problem.
There really isn't much to explain here, you have a resource file (e.g. icon.qrc
), then you call pyrcc4 -o icon_rc.py icon.qrc
which will create a module icon_rc.py
which you then can import in your project.
It's all documented here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With