Writing for PyQt5 & PySide2

Great post Martin! I think you can also use the EAFP approach, and do something like this:

# PyQt5
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtCore import pyqtSignal as Signal, pyqtSlot as Slot
except ImportError:
# PySide2
from PySide2 import QtGui, QtWidgets, QtCore
from PySide2.QtCore import Signal, Slot

In the qt.py file.
What do you think?

Thanks for the comment and good point! This works great for applications where you want to support it running on either binding.

Just a warning though, it might not work so great if you’re writing a library where your library is imported by an app using PySide2 but PyQt5 is available in site packages. Bit of an edge case, but exactly the weird things that happen when you write and distribute a library :slight_smile: