Skip to content

RecursionError while setting matplotlib backend #148

Open

Description

@szymonk211

In Pycharm ipython console with attached debuger:

import matplotlib  
matplotlib.use("TkAgg")

causes import error:

Traceback (most recent call last):
File "/home/greensort/miniconda2/envs/borowka_fix/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
matplotlib.use("TkAgg")
File "/home/greensort/pycharm-community-2019.1.1/helpers/pydev/pydev_ipython/matplotlibtools.py", line 70, in patched_use
matplotlib.real_use(*args, **kwargs)
File "/home/greensort/pycharm-community-2019.1.1/helpers/pydev/pydev_ipython/matplotlibtools.py", line 70, in patched_use
matplotlib.real_use(*args, **kwargs)
File "/home/greensort/pycharm-community-2019.1.1/helpers/pydev/pydev_ipython/matplotlibtools.py", line 70, in patched_use
matplotlib.real_use(*args, **kwargs)
[Previous line repeated 2982 more times]
RecursionError: maximum recursion depth exceeded

Activity

  1. floyebolu commented on Oct 4, 2019

    @floyebolu

    I'm also having a similar issue. The problem is in the patch_use function in pydev/pydev_ipython/matplotlibtools.py.
    It appears what is happening is that matplotlib.real_use is being overwritten with patched_use on some subsequent call of matplotlib.use which leads to an infinite loop.

    My intuition is that a fix would involve changing these lines:

    matplotlib.real_use = matplotlib.use
    matplotlib.use = patched_use

    to:

    try:
        real_use = matplotlib.real_use
    except AttributeError:
        matplotlib.real_use = matplotlib.use
    finally:
       matplotlib.use = patched_use

    The try-block is to catch if the real_use attribute exists or not. If it already exists it won't be overwritten.

  2. davisidarta commented on Jul 10, 2020

    @davisidarta

    I'm also having this issue. Any progress on this?

  3. davisidarta commented on Jul 11, 2020

    @davisidarta

    Needed a full OS reinstall to solve the issue, since no other solution appeared. Everything working fine on Ubuntu 20.

  4. janaben commented on Mar 28, 2023

    @janaben

    I ran into this exact problem today and the solution suggested by @floyebolu worked perfectly.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions