[PyQt] Problem with resource imports in pyuic generated files

Elvis Stansvik elvstone at gmail.com
Tue Feb 16 12:31:27 GMT 2016

2016-02-16 13:25 GMT+01:00 Elvis Stansvik <elvstone at gmail.com>:
> I have the following setup in my distribution (cut down to show the essentials):
> orexplore.gui/
>     orexplore/gui/ui/main_window.ui  --pyuic5-->
> orexplore/gui/ui/main_window_ui.py
>     resources/icons.qrc  --pyrcc5-->  orexplore/gui/resources/icons_rc.py
> That is, orexplore.gui is the top-level distribution directory. The
> orexplore/ subdirectory is my main Python package. In resources/ I
> keep .qrc files (kept outside the package source tree), and in
> orexplore/gui/ui I have my .ui files (kept as part of the package
> source tree).
> The problem is that if, in Designer, I set the icon for the main
> window in main_window.ui to be an icon from the resources/icons.qrc
> resource, then pyrcc5 --from-imports will generate an import statement
> from . import icons_rc
> which obviously won't be found. How can I make it generate:
> from orexplore.gui.resources import icons_rc
> ? Is there something I can do in the .ui and/or .qrc?
> If I omit the --from-imports, It'll just generate:
> import icons_rc
> which also won't be found (it would need to be import
> orexplore.gui.resources.icons_rc for that to work).
> Very grateful for any advice.

In short: I'm looking for a way to tell pyuic5 in which package my
generated resources can be find, since it obviously can't know this,
from just looking at the

<iconset resource="../../../resources/icons.qrc">

in the .ui file. The above is a relative file path from the .ui, added
by Designer, while my imports statements should be relative to the
Python package path, which is orexplore.gui.resources.


> Elvis

More information about the PyQt mailing list