[PyQt] Problem with resource imports in pyuic generated files

Elvis Stansvik elvstone at gmail.com
Tue Feb 16 12:25:52 GMT 2016


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.

Elvis


More information about the PyQt mailing list