[PyQt] Problem with resource imports in pyuic generated files

Baz Walter bazwal at ftml.net
Tue Feb 16 18:35:23 GMT 2016


On 16/02/16 12:25, Elvis Stansvik wrote:
> 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.

A common directory structure would be something like this:

container_dir/

   designer_files/
     main_window.ui

   icons/
     app_icon.png
   resources.qrc

   python_package/
     ui/
       main_window.py
       resources_rc.py
     app_logic.py
   main.py

So the python package directory contains python modules and nothing 
else. The resource module generated by pyrcc just goes in the same 
directory as the ones generated by pyuic, which solves the import issue.

-- 
Regards
Baz Walter


More information about the PyQt mailing list