Correct way to load .ui files?

Colin Macdonald cbm at math.ubc.ca
Mon Nov 25 04:22:07 GMT 2024


I've been using "from PyQt6 import uic" and this works just fine with 
your libraries from `pip install pyqt6`.

But I've just found that this does not work out-of-the-box on Debian 
12.8 and Ubuntu 24.04.

For example:

$ docker pull debian:trixie
$ docker run -it --rm debian:trixie
$ apt update
$ apt install python3-pyqt6
$ python3 -c "from PyQt6 import uic"
Traceback (most recent call last):
   File "<string>", line 1, in <module>
ImportError: cannot import name 'uic' from 'PyQt6' 
(/usr/lib/python3/dist-packages/PyQt6/__init__.py)

- - - -

My real code looks something like this:

from PyQt6 import uic

class XYZ(QDialog):
     def __init__(self):
         super().__init__()
         uic.loadUi("xyz.ui", self)

Perhaps that isn't quite right?  I don't recall where I learned this, 
perhaps https://www.pythonguis.com/tutorials/pyqt6-first-steps-qt-designer/

Maybe I should go back to `pyuic6` approach instead?

Or is this something to file an issue with the Debian folks?

thanks,
Colin

-- 
Colin Macdonald
Associate Professor
Dept of Math, UBC



More information about the PyQt mailing list