PyQt - Unable to import resource module!


#1

So I’m working on a PyQt user-interface and I got most things working (converted all Qt Designer files, got my custom CSS up and running, entire UI runs, etcetera) - except that resource file.

It seems that no matter how I try and get this working, my UI.py module just can’t seem to be able to find the resources.py module even though they reside in exactly the same folder.

I have converted my Qt Designer files like this:

python3 pyuic5.exe -x some_path\my_stuff.ui -o some_path\my_stuff.py
python3 pyrcc5.exe some_path\resources.qrc -o some_path\resources.py

Odd thing I notice is that in the generated UI file (my_stuff.py) is that the converter (pyuic) adds a suffix to the resource -module import:

import resources_rc

I never asked for this, and nowhere in Qt Designer can I find this prefix! But either way: I manually changed that in the UI file (bad, I know - because that file is auto-generated so changes are lost if I re-convert obviously):

import resources

But strangely enough this does not work!
ImportError: No module named ‘resources’

I did a print(file) in my UI module just to make sure that it’s actually located/run where I want it and sure it is. The module sits there in it’s folder right next to the resource module but for some odd reason it still can’t import it :frowning:

EDIT:
I’ve looked around for solutions, like the one described here:


…however, this does not solve my problem. Excluding the resource -tag in the .ui file only results in the import-statement getting removed from the generated UI.py file. Then, manually adding import resources gives me the same problem as before.
Also, having to edit auto-generated file is not a solution!

EDIT2:
Resources load if I manually edit the auto-generated UI.py file and add the full namespaced path to the resource module, like:
import uncel.dolan.resources

It’s a hacky fix though and not a good solution for the long run since that UI.py file is auto-generated…