-2

I am in the process of updating code for Py2/Py3 compatibility. Some of the original Python 2.7 code uses PyQt4. The standard Python 3.7 installation which we will be implementing incrementally on our users' systems is not compatible with PyQt4.

In my research, I have found a host of various involved and often convoluted methods of making Python 2.7 play nicely with PyQt5, but this is an untenable solution as the whole reason for the cross-compatibility update is so that:

  • users whose systems have not been updated can continue to use the updated modules/packages
  • developers will only have to maintain a single version, not a Py2 version and a Py3 version

I have not found much at all that helps with making Python 3.7 talk to PyQt4, so the backwards compatible solution, though preferable, does not seem tenable, either, unless I am (hopefully) mistaken.

Another alternative is to modify the code to check Python versions and do the imports accordingly with if/else or try/except statements.

I would like to know what the best and simplest method is for cross-compatible coding for PyQt4/5 so that the users (most of whom are NOT developers) will have little to no difficulty updating and will NOT need to make changes to their systems to continue to use updated programs before their systems are updated for them.

CNIDog
  • 374
  • 3
  • 18
  • Both Qt4 and PyQt4 are obsolete and no longer supported. The same will very soon be true for Python2. Any system that still relies on those libraries has been fundamentally broken for *years*. – ekhumoro Oct 10 '19 at 18:02
  • @ekhumoro - Thanks. That is why we are (finally) doing the update. However, since there are many users, we are being asked to make the changes to the code first, then update the users' computers one by one to Py3. Users not yet updated will use the same code base as the updated users so that developers (who still make frequent updates and mods to the code as requirements change) only need to maintain a single version - so it all needs to be cross-compatible. It will all be done and moot in a couple of months, but for now I wanted to get a professional opinion on the best way to proceed. – CNIDog Oct 10 '19 at 19:31

1 Answers1

0

While [Py]Qt4 is obsolete, I know that, in somehow large or specific environments, system updates cannot be possible or easily done in the near future. I'd suggest you to use Qt.py, which is a "shim" that makes possible to use (almost) transparently all Qt bindings (PySide 1/2 and PyQt 4/5) for both Python 2 and 3.

The overall benefit is pretty simple: you will be able to use PyQt5-ready code, while keeping it usable on older systems that still have to rely on PyQt4.

The most important work you'll need to do is to change all QWidget subclasses as part of QtWidgets module instead of QtGui, and remember that Qt.py automatically attempts to use sip API v2 (which makes all toPyObject conversions unnecessary and much more transparent).
Keep in mind that some classes require manual import from the current binding and obviously there are some differencies in behavior, but besides that, it will make the whole migration much more easier.

musicamante
  • 41,230
  • 6
  • 33
  • 58