Skip to content

If one binding has already been imported, then qtpy should just use it #138

Closed

Description

@anntzer

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

  1. ccordoba12 commented on Jan 30, 2018

    @ccordoba12
    Member

    Could you submit a pull request for this? We have no problem to include it in our next release.

  2. added this to the v1.4 milestone on Jan 30, 2018
  3. anntzer commented on Jan 30, 2018

    @anntzer
    ContributorAuthor

    will do (... at some point...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions