I'm trying to follow steps from QGIS plugin creation tutorials.
- Working with QGIS LTR (3.22.13-2)
- Located at: [C:\OSGeo4W\bin]
Using the QGIS Plugin Builder, I get the (seemingly common) error, that "There was an error compiling. Compile it manually using pyrcc5.". I get stuck at the point where I'm supposed to compile with:
pyrcc5 -o resources.py resources.qrc
However, the plugin builder doesn't create a resources.qrc
in the plugin folder. Therefore I get the error "C:\OSGeo4W\apps\Python39\Scripts\pyrcc5: File does not exist 'resources.qrc'"
The pyrcc5 works just fine (I tested it on existing plugins, which contain a resources.qrc
file and it ran without errors). I'm puzzled though on how I'm supposed to proceed without the resources.qrc. It seems trivial, but since I have no experience, I have no idea whether I should just create an empty one? Apparently it's listing files that are used by the plugin, but can I just omit this step when not using any particular files?
According to various tutorials/threads online, the following compile.bat
script is supposed to be created:
@echo off
call "C:\OSGeo4W\bin\o4w_env.bat"
call "C:\OSGeo4W\bin\qt5_env.bat"
call "C:\OSGeo4W\bin\py3_env.bat"
@echo on
pyrcc5 -o resources.py resources.qrc
qt5_env.bat
and py3_env.bat
are not found, but according to according to this question also no longer needed.
Best Answer
I may have found the "solution" myself: I selected to build a Processing Provider plugin.
I assume it uses the Processing interface, therefore no QT resources (interface elements) are generated (resources.qrc). When choosing "Tool button with dialog", everything works smoothly as expected and described in the tutorials: resources.qrc is properly generated and the compiling process seems to work fine, as resources.py is also generated and no errors occur.
The compiling error I am getting when building a processing provider is simply misleading for unexperienced users:
I spent a few hours trying to find resources.qrc, fixing my PATH, reinstalling QGIS, trying to understand the compilation and testing pb_tool, although everything was working fine in the first place.
As there is no resources.qrc file needed, no compilation is necessary. The plugin can simply be copied to the plugin directory (e.g. C:\Users{user name}\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins ) without compilation and works fine. This holds true at least for the template that plugin builder generates. Once the plugin gets more complex and uses files, the compilation may be necessary.
I also created a dummy resources.qrc with the basic structure in the processing provider plugin:
When compiling, this simply generates the "warning":
No resources in resource description.
I think it would be a better solution for the plugin builder in case of processing provider (rather than not generating resources.qrc) at all: It avoids the misleading compilation error, may be needed later anyways and also "tests"/"confirms" that the pyrcc5 compiler is found. I raised a github-issue, maybe this will get resolved in the future.