Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get a list of errors when trying to load matplotlib in PyCharm with the Anaconda environment?

I have installed PyCharm with Anaconda. I installed numpy fine using the PyCharm settings by adding the package via the Project Interpreter tab. However I am now trying to install matplotlib and I get a list of errors.

Just by including the line

import matplotlib.pyplot as plt

I get the errors:

AttributeError: module 'matplotlib.pyplot' has no attribute 'switch_backend'
Matplotlib support failed
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 23, in do_import
    succeeded = activate_func()
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 199, in <lambda>
    "matplotlib": lambda: activate_matplotlib(self.enableGui),
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\pydev_ipython\matplotlibtools.py", line 96, in activate_matplotlib
    gui, backend = find_gui_and_backend()
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\pydev_ipython\matplotlibtools.py", line 47, in find_gui_and_backend
    backend = matplotlib.rcParams['backend']
  File "C:\Users\calcl\Anaconda3\envs\PXP\lib\site-packages\matplotlib\__init__.py", line 892, in __getitem__
    plt.switch_backend(rcsetup._auto_backend_sentinel)

What could be causing this problem and how would I resolve it?

I am using Python 3.6 with 3.0.0 Matplotlib and PyCharm 2018.2.4

like image 279
Cameron Avatar asked Oct 17 '18 17:10

Cameron


People also ask

Why is Matplotlib not available in Anaconda?

This is because matplotlib has no 3.9 wheels .. For convenience in the use of matplotlib, you can install anaconda. In anaconda environment matplotlib, numpy and pandas are available by default for Python installed in Anaconda. Or you can use lower versions of Python. cd matplotlib python -mpip install .

Why am I getting different import errors when using matplotlib?

@jenshnielsen I only have one line code import matplotlib.pyplot as plt Ok that might be python version difference giving different import errors. The most likely reason is that you are running your scripts with a different python interpreter than the one that you are using from the command line (with the -c option).

Is there a Python package called Pyplot?

But anyway there is no python package called pyplot. You want to install matplotlib pip install matplotlib and import matplotlib.pyplot as plt from python Sorry, something went wrong.

Why pip-21 doesn't install Matplotlib?

Successfully installed pip-21.3.1 again it didn't install Matplotlib. Hence Down-versioned Python to 3.9 and installed Matplotlib. For Python version upto 3.9 wheel is defined for Matplotlib, do use Python 3.9 and make sure pip is upgraded to available version it wont be problem to install matplotlib


1 Answers

Like @BigFish wrote, this is a bug in PyCharm side, you can see the bug report here.

It's fixed in PyCharm 2018.3, so the easiest solution is to upgrade PyCharm. Alternative workarounds are downgrading matplotlib, or unchecking "run with python console" in the run configuration:

run with console

This will allow you to run/debug, but you'll still get those errors if you use the interactive console.

As a side note, PyCharm has a history of lagging behind matplotlib API changes, so this should be your first guess next time...

like image 92
OmerB Avatar answered Sep 17 '22 08:09

OmerB