Various Issues with PyQt6
kovid at kovidgoyal.net
Tue Mar 2 03:40:44 GMT 2021
> And since we are here, is the shorthand Qt module for importing from
> one namespace really going away in PyQt6? I get
> ModuleNotFoundError: No module named 'PyQt6.Qt'
Fortunately, this too is trivial to fix thanks to the ability to
override __getattr__ for modules in python 3.7+. Now in calibre, I can
just import any PyQt5 thing using
from qt.core import whatever
from qt.webengine import whatever
And if I decide to switch to PyQt6 or PySide or anything else, it's a
one line change. And I dont need to keep track of which module contains
which class. Or have multiple import statements for PyQt.
And thanks to auto generated .pyi files, autocompletion even works with jedi.
If anyone is interested, here is the wrapper code to make it happen
Just copy that directory onto your PYTHONPATH. You can regenerate/update
it by simply running python /path/to/qt/folder.
Look inside __main__.py for the list of Qt modules that are placed into
each namespace. The list is suited for calibre, adjust to your needs.
Dr. Kovid Goyal
More information about the PyQt