2

I'm having an issue in pycharm while running my debugger : "AttributeError: module 'IPython' has no attribute 'get_ipython'"

The problem is that I don't know what IPython is, I'm not using it, and when i clink on the first link in the error log, I arrive in a file that is not even mine.

More, if I run my code without debugger, this error do not appear.

Here is the full trace : enter image description here

It looks like this come from matplotlip but it doesn't really help me.

Thank you for any help

2
  • That bug is so annoying, need help there too.... Commented Mar 26, 2021 at 10:41
  • Remade my conda environment and the error went away.. hmm.. Commented Sep 16, 2021 at 2:30

2 Answers 2

1

I'm also very annoyed about this bug so I tried some stuff and found a workaround (not clean though...).

I work with venv environments so I just changed the file/code which throws the error.

Go to backend_bases.py. For me it's: \venv\Lib\site-packages\matplotlib\backend_bases.py. Or just click on the last stacktrace.

In line 1744 you find this code:

if sys.modules.get("IPython") is None:
    return

Change it and add an else: return statement.

if sys.modules.get("IPython") is None:
    return
else:
    return

When running without debugger the code does the same so I think that's ok. I don't get an error anymore with this change.

Sign up to request clarification or add additional context in comments.

1 Comment

sounds good, I test it as soon as I can thanks !
0

So, I finally resolve it.

I valid the answer of Andrej because he's method was good, directly modify the matplotlib files in the venv, but my file was a bit different from his one.

In my file, the code around line 1713 looked like this.

import IPython
ip = IPython.get_ipython()
if not ip:
    return

I simply replace it by this:

import IPython
if hasattr(IPython, "get_ipython"):
    ip = IPython.get_ipython()
else:
    return
if not ip:
    return

To make sure the function exist before to call it.

This was finally so simple, I was just scare to edit my venv by myself ^^.

Thx a lot

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.