You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
If one binding has already been imported, then qtpy should just use it #138
Consider, for example, a system where solely pyqt4 and pyqt5 are installed. If one does
import PyQt5.QtGui
import qtpy
this fails with
qtpy.PythonQtError: No Qt bindings could be found
(even though obviously there is a Qt binding available) because PyQt4.QtGui cannot be imported at all after PyQt5.QtGui has already been imported.
Fortunately there is an easy solution, which is to check, before doing anything else, whether PyQt4/5/PySide/2 are already present in sys.modules, and, if one of them is, just use it.
Real use case:
matplotlib (which can use any of the bindings) is considering switching from using its own qt shim to qtpy. However, it is not rare that one user specifies a given binding to use (via the matplotlibrc backend param), but sometimes wants to use some GUI program that is explicitly written (solely) against PyQt5. Then starting the GUI will import PyQt5 and matplotlib would fail to initialize its backend if it did not first check whether a given binding had already been forced for the process.
Activity
ccordoba12 commentedon Jan 30, 2018
Could you submit a pull request for this? We have no problem to include it in our next release.
anntzer commentedon Jan 30, 2018
will do (... at some point...)