I am using the QGIS plugin builder 3 with Qt Designer to create the GUI for my plugin. I've got a basic GUI done with QtDesigner and I need to dynamically populate a container in my GUI using python. I am struggling to write the python code for this without having a proper look at the python file generated by the builder using the .ui file. I've tried doing it manually using commands like the following:

C:\path_to_pyuic\pyuic.py -o ui_form.py form.ui

When I do this, it struggles to find PyQT related packages. I get the following error:

No module named PyQt5

But when I run the plugin on QGIS, the GUI pops up perfectly and everything runs smooth. It would be great if someone can point out a quick and easy way to access the .py file generated by the builder. I am not super sure if it is actually generated but it would be ideal if it is accessible in some way.

  • 1
    The following works fine for me under Windows in OSGeo4W shell: cd C:\path\to\location\of\form.ui then pyuic5 form.ui -o form.py I haven't used plugin builder for quite a while but iirc, it doesn't convert .ui to .py but rather uses uic.loadUiType() method, which you can see in the generated file: plugin_name_dialog.py. BTW did you change the .ui name? I thought plugin builder generated .ui file is usually named like: plugin_name_dialog_base.ui.
    – Ben W
    Dec 20, 2021 at 7:03
  • Generally you access gui elements in you main plugin file like self.dlg.objectName. You can inspect or edit the object names and classes in your .ui file inside QtDesigner. Once you have a reference to your ui objects, you can access any PyQt methods belonging to the object class or parent classes.
    – Ben W
    Dec 20, 2021 at 7:09
  • Thanks for your reply! When I run pyuic5 form.ui -o form.py on the OSGeo4W shell, I get 'pyuic5' is not recognized as an internal or external command. Any ideas to fix this?
    – Ravindu
    Dec 21, 2021 at 5:35
  • Which version of QGIS are you using? Did you install QGIS with OSGeo4W installer?
    – Ben W
    Dec 21, 2021 at 5:56
  • pyuic5 should be in scripts folder of the python installed with QGIS e.g. C:\OSGeo4W\apps\Python39\Scripts.
    – Ben W
    Dec 21, 2021 at 6:11


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.