X Tutup
Skip to content

Matplotlib attempts to import PyQt4 when PyQt5 is not available #8312

@cpcloud

Description

@cpcloud

Bug report

Bug summary

  • matplotlib is falling back to PyQt4 when importing PyQt5 fails.
  • PyQt5 can fail to import for reasons other than not being installed. For example, if dlopening any of the transitive shared object dependencies of PyQt5 fails (happy to dive into the details of how and why this happens, if needed), ImportError is raised.

Code for reproduction

Unfortunately, this case is specific to the installation that I'm working with which is doing some unconventional things. I'm able to reproduce the bug, but not outside the environment I'm working in, and I can't share any code.

Actual outcome

matplotlib attempts to import PyQt5, which fails because QtGui cannot be loaded by dlopen. This causes matplotlib to think that PyQt5 isn't available, because failing dlopen calls raise an ImportError and subsequently matplotlib will attempt to import PyQt4.

Expected outcome

If I say my backend is Qt5Agg, that's what I mean. I'd like to know if the backend I've requested is not available, so I can take action to remedy the situation.

Matplotlib should examine the error message of the raised ImportError and reraise if it's not the standard ImportError: No module named 'PyQt5' I-haven't-installed-something-properly error message. It's very unfortunate that dlopen failures during the course of import are ImportErrors, but that ship has sailed.

Matplotlib version

  • matplotlib: 2.0.0
  • python: 3.5.3
  • platform: linux
  • I installed matplotlib through the default anaconda channel

I'm happy to put a patch up for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup