在Anaconda环境中尝试在PyCharm中加载matplotlib时,为什么会出现错误列表? [英] Why do I get a list of errors when trying to load matplotlib in PyCharm with the Anaconda environment?

查看:132
本文介绍了在Anaconda环境中尝试在PyCharm中加载matplotlib时,为什么会出现错误列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Anaconda中安装了PyCharm.我通过PyCharm设置安装了numpy fine,方法是通过项目解释器"选项卡添加软件包.但是,我现在正在尝试安装matplotlib,但出现了错误列表.

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.

只需包含该行

将matplotlib.pyplot导入为plt

我收到错误:

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?

我正在将Python 3.6与3.0.0 Matplotlib和PyCharm 2018.2.4一起使用

I am using Python 3.6 with 3.0.0 Matplotlib and PyCharm 2018.2.4

推荐答案

我在使用带有3.0.0 Matplotlib和PyCharm 2018.2.4的Python 3.6时遇到了相同的错误.错误显然是在 Pycharm 方面,如回溯和通过 anaconda 提示符或 spyder IDE 导入 matplotlib 不会产生此错误的事实所示.

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.

根据 matplotlib 的发行说明,'switch backend' 实用程序似乎是一项新功能 https://github.com/matplotlib/matplotlib/releases.正如@Psychotechnopath 的回答中所指出的,路径可能存在一些问题,因此当 Pycharm 脚本在您的 Traceback 中调用它时,Pycharm 无法找到 switch 后端模块.

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.

但是,我不认为手动向路径添加任何内容是理想且可靠的解决方案.相反,我使用Anaconda Prompt中的conda安装程序将matplotlib降级到2.2.3版:

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

在这次降级之后,我能够再次在 Pycharm 中导入 matplotlib,没有任何问题.

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

这篇关于在Anaconda环境中尝试在PyCharm中加载matplotlib时,为什么会出现错误列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆