[PySide] Help importing compiled Qt resource file from subfolder

Adrian Herrmann adrian.herrmann at qt.io
Thu Sep 28 13:34:05 CEST 2023

Hello Henry,

for your current project structure it appears that this line in helpers.py would be enough for the import to work:

      from images.compiledresource_rc import someFunction

This should work regardless of the working directory, as long as helpers.py is imported from main.py, because the directory that main.py sits in is always added to PYTHONPATH.

Let us know if you have further questions or problems.
Best regards,

Adrian Herrmann

Software Engineer, Qt for Python

Qt Group
Erich-Thilo-Str. 10 12489
Berlin, Germany

adrian.herrmann at qt.io

+49 1578 0598682


Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/facebook-x2-right_2023-03-01-095511_zhlr.png]<https://www.facebook.com/qt/>     [https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/twitter-x2.png] <https://twitter.com/qtproject>         [https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/linkedin-x2.png] <https://www.linkedin.com/company/qtgroup/>    [https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/youtube-x2.png] <https://www.youtube.com/QtStudios>

Von: PySide <pyside-bounces at qt-project.org> im Auftrag von henry.wede--- via PySide <pyside at qt-project.org>
Gesendet: Montag, 25. September 2023 01:00
An: pyside at qt-project.org
Betreff: [PySide] Help importing compiled Qt resource file from subfolder


I have spend the last few hours trying to figure this out and now I have to ask for some help.

My project has grown to the point where is needs to be more organized, so I am moving modules from one huge folder into subfolders.  I use a resource file in QtDesigner and then compile it resulting in a "something_rc.py".  With the "one huge folder" approach I just imported this file into any module that uses dialogs - this is the only way that the images would show up in the widgets.  Now I am struggling to do this with the folder structure.

I made a simple example that shows the issue.  The tree is below and the attached zip file contains everything.

│   main.py
│   test_local.py
│       compiledresource_rc.py

Briefly, main can import test_local and util without any problems.  The issue is that if helpers needs to import the compiled resource file compiledresource_rc.  I swear that I have tried the exact syntax from different Internet resources and I cannot get it to work.

Can somebody please help me deal with this resource file?

Thank you for your help,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20230928/6ec29224/attachment.htm>

More information about the PySide mailing list