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

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...


I encountered the same error using Python 3.6 with 3.0.0 Matplotlib and PyCharm 2018.2.4. The error is evidently on the Pycharm side, as indicated by the traceback and by the fact that importing matplotlib via the anaconda prompt or spyder IDE does not produce this error.

The 'switch backend' utility seems to be a new feature according to the release notes of matplotlib https://github.com/matplotlib/matplotlib/releases. As pointed out in @Psychotechnopath's answer, it might be some issue with the path, so that Pycharm can't find the switch backend module when it is called by the Pycharm scripts in your Traceback.

However I don't think manually adding anything to the path is a desirable and robust solution. Instead, I downgraded matplotlib to version 2.2.3 using the conda installer in the Anaconda Prompt:

conda install matplotlib=2.2.3

After this downgrade I was able to import matplotlib in Pycharm again without any issues.