Skip to content

Only print actually tested QT APIs when erroring #25772

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

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

ksunden
Copy link
Member

@ksunden ksunden commented Apr 26, 2023

PR Summary

After I closed #25673 because the root cause of that issue is in IPython mapping "qt" to "qt5agg", I realized that perhaps we could still do better about our error message.
While this change would not have actually resolved the question of "what is asking this to be qt5??", it would have at least not also raised the question of "why is qt6 not working? It is installed."

>>> plt.switch_backend("qtagg")
Traceback (most recent call last):
...
ImportError: Failed to import any of the following Qt binding modules: PyQt6, PySide6, PyQt5, PySide2
>>> plt.switch_backend("qt5agg")
Traceback (most recent call last):
...
ImportError: Failed to import any of the following Qt binding modules: PyQt5, PySide2

Now only outputs the bindings which were actually tested, rather than all 4 regardless of whether only qt5 bindings were tested.

PR Checklist

Linked Issue

  • [N/A] Added "closes #0000" in the PR description to link it to the original issue.

Documentation and Tests

  • [N/A] Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Copy link
Contributor

@kwsp kwsp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. This would definitely help future users narrow down the problem.

@tacaswell
Copy link
Member

Can we add a test? I think this is testable using the sub-process trick and doing sys.modules['PyQt5'] = None and so forth to ensure that a given binding is non-importable.

@kwsp
Copy link
Contributor

kwsp commented Apr 26, 2023

Can we add a test? I think this is testable using the sub-process trick and doing sys.modules['PyQt5'] = None and so forth to ensure that a given binding is non-importable.

elif sys.modules.get("PyQt5.QtCore"):

Do you mean sys.modules['PyQt5.QtCore'] = None?

@tacaswell
Copy link
Member

Do you mean sys.modules['PyQt5.QtCore'] = None

The way Python importing works if you set the top level package to None in sys.modules then none of the sub-packages will be importable either. It would work to go all the way down to the ones we test, but they would not simulate "not installed" the same way blanking out the top level one would.

@tacaswell tacaswell added this to the v3.8.0 milestone Apr 26, 2023
@ksunden
Copy link
Member Author

ksunden commented Apr 27, 2023

Added a test, put it in test_backends_interactive because that is where _run_helper is and other similar tests are located there (e.g. asserting that qt5agg actually uses qt5)

@QuLogic QuLogic merged commit cb7f649 into matplotlib:main Apr 27, 2023
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

Successfully merging this pull request may close these issues.

[Bug]: VSCode matplotlib interactive mode cannot import Qt bindings
4 participants