Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cpcloud opened this issue Mar 17, 2017 · 4 comments
Closed

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

cpcloud opened this issue Mar 17, 2017 · 4 comments

Comments

@cpcloud
Copy link

cpcloud commented Mar 17, 2017

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.

@anntzer
Copy link
Contributor

anntzer commented Mar 17, 2017

I would support having qt5agg mean exactly that but 1. you need to be check the QT_API environment variable as well and 2. there may be backcompatibility issues.

@cpcloud
Copy link
Author

cpcloud commented Mar 17, 2017

The existing code is fine, except for this fallback code. I think it could go through a deprecation cycle as well to address major back compat issues

@anntzer
Copy link
Contributor

anntzer commented Mar 17, 2017

Please do submit a patch if you can.

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Mar 17, 2017
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Mar 17, 2017
@tacaswell
Copy link
Member

The source of this is: #5153 which is to play nice with people directly using qt_compat and the qt* backends without setting the rcparams.

I suspect the best fix here is to add (yet another) flag to this so we only fall back if we are in the list. Put in a PR because that was faster than explaining how I thought it should be fixed.

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@tacaswell tacaswell modified the milestones: 2.0.2 (critical bug fixes from 2.0.1), 2.0.3 (next bug fix release) May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants