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

[Bug]: 3.6.0 doesn't interact well with pycharm throwing "backend_interagg" exception #23911

Closed
ucfbrd opened this issue Sep 16, 2022 · 13 comments · Fixed by #23912 or #24019
Closed

[Bug]: 3.6.0 doesn't interact well with pycharm throwing "backend_interagg" exception #23911

ucfbrd opened this issue Sep 16, 2022 · 13 comments · Fixed by #23912 or #24019

Comments

@ucfbrd
Copy link

ucfbrd commented Sep 16, 2022

Bug summary

While using Pycharm and matplotlib 3.6.0 as soon as we import matplotlib, the interpreter crash

Code for reproduction

import matplotlib.pyplot as plt
plt.figure(1)

Actual outcome

    canvas_class = backend_mod.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'

Expected outcome

same thing works with version 3.5.2

Additional information

No response

Operating system

No response

Matplotlib Version

3.6.0

Matplotlib Backend

module://backend_interagg

Python version

3.8

Jupyter version

No response

Installation

No response

@ucfbrd ucfbrd changed the title [Bug]: [Bug]: 3.6.0 doesn't interact well with pycharm throwing "backend_interagg" exception Sep 16, 2022
@tacaswell tacaswell added this to the v3.6.1 milestone Sep 16, 2022
@tacaswell
Copy link
Member

Does this change make it work?

✔ 14:16:01 $ git diff
diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py
index f5c86de126..1e94d90d15 100644
--- a/lib/matplotlib/pyplot.py
+++ b/lib/matplotlib/pyplot.py
@@ -263,7 +263,6 @@ def switch_backend(newbackend):

     backend_mod = importlib.import_module(
         cbook._backend_module_name(newbackend))
-    canvas_class = backend_mod.FigureCanvas

     required_framework = _get_required_interactive_framework(backend_mod)
     if required_framework is not None:
@@ -293,6 +292,8 @@ def switch_backend(newbackend):
     # also update backend_mod accordingly; also, per-backend customization of
     # draw_if_interactive is disabled.
     if new_figure_manager is None:
+        # only try to get the canvas class if have opted into the new scheme
+        canvas_class = backend_mod.FigureCanvas
         def new_figure_manager_given_figure(num, figure):
             return canvas_class.new_manager(figure, num)

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Sep 16, 2022
This is to un-break pycharm's backend_interagg

Closes matplotlib#23911
@TLCFEM
Copy link

TLCFEM commented Sep 16, 2022

I do not think this PR fixes the problem, after applying the changes, now exception is thrown on Line 185

line 185, in _get_required_interactive_framework
    if not hasattr(backend_mod.FigureCanvas, "required_interactive_framework"):
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?

@TLCFEM
Copy link

TLCFEM commented Sep 16, 2022

One more check needs to be added:

def _get_required_interactive_framework(backend_mod):
    if not hasattr(backend_mod, 'FigureCanvas') or not hasattr(backend_mod.FigureCanvas, "required_interactive_framework"):
        _api.warn_deprecated(
            "3.6", name="Support for FigureCanvases without a "
            "required_interactive_framework attribute")
        return None
    # Inline this once the deprecation elapses.
    return backend_mod.FigureCanvas.required_interactive_framework

@QuLogic
Copy link
Member

QuLogic commented Sep 17, 2022

I don't believe the latter check was implemented.

@QuLogic QuLogic reopened this Sep 17, 2022
@TLCFEM
Copy link

TLCFEM commented Sep 17, 2022

I don't believe the latter check was implemented.

No, it's not.

@HarmvandenBrand
Copy link

Can confirm this is still an issue with matplotlib 3.6.0 on python 3.10 in PyCharm 2022.2.2

@nfeliccia
Copy link

Not working on PycharmPro

image

import matplotlib.pyplot as plt

pizza, marshmallows = plt.subplots(1, 1)
print(pizza)

Error


Traceback (most recent call last):
  File "F:\gt_stats_iii\scipy_stats_binom_examples.py", line 8, in <module>
    pizza, marshmallows  = plt.subplots(1, 1)
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 1430, in subplots
    fig = figure(**fig_kw)
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 771, in figure
    manager = new_figure_manager(
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 346, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 336, in _warn_if_gui_out_of_main_thread
    if (_get_required_interactive_framework(_get_backend_mod()) and
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 206, in _get_backend_mod
    switch_backend(dict.__getitem__(rcParams, "backend"))
  File "F:\gt_stats_iii\venv\lib\site-packages\matplotlib\pyplot.py", line 266, in switch_backend
    canvas_class = backend_mod.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?

Process finished with exit code 1

@mposter1
Copy link

mposter1 commented Nov 8, 2023

Problem still occurring in PyCharm for me. Still requires FigureCanvas on backend module, running matplotlib 3.8.1. See line 342 of pyplot.py

@ksunden
Copy link
Member

ksunden commented Nov 8, 2023

Not having a FigureCanvas class as a backend was deprecated in mpl 3.6 and expired in 3.8, it looks like the most recent versions of PyCharm do have it, so perhaps you need to update?

@QuLogic
Copy link
Member

QuLogic commented Nov 8, 2023

AFAICT, JetBrains added those values over a year ago, but I cannot tell from the tags exactly what version that means.

@mposter1
Copy link

mposter1 commented Nov 9, 2023

Update fixed. Thanks.

@benyoung-libenyang
Copy link

屏幕截图 2023-11-10 093046
maybe you cloud try.

@oukohou
Copy link

oukohou commented Dec 19, 2023

屏幕截图 2023-11-10 093046 maybe you cloud try.

great,this fixed my problem.

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