Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYQT4 - How do I compile and import a qrc file into my program?

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.

like image 547
Thomas Avatar asked Apr 07 '13 16:04

Thomas


People also ask

How do I use QRC in PyQt5?

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.

What is pyrcc5?

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.


2 Answers

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.

like image 142
Thomas Avatar answered Sep 17 '22 12:09

Thomas


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.

like image 44
mata Avatar answered Sep 16 '22 12:09

mata