Jam*_*mes 7 python matplotlib pycharm
我已经安装了PyCharm和Anaconda.我通过Project Interpreter选项卡添加包,使用PyCharm设置安装了numpy fine.但是我现在正在尝试安装matplotlib,我得到一个错误列表.
只是包括这条线
import matplotlib.pyplot as 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)
Run Code Online (Sandbox Code Playgroud)
什么可能导致这个问题,我将如何解决它?
我使用Python 3.6与3.0.0 Matplotlib和PyCharm 2018.2.4
我使用Python 3.6与3.0.0 Matplotlib和PyCharm 2018.2.4遇到了同样的错误.错误显然是在Pycharm方面,如回溯以及通过anaconda提示符或spyder IDE导入matplotlib不会产生此错误这一事实.
根据matplotlib https://github.com/matplotlib/matplotlib/releases的发行说明,"切换后端"实用程序似乎是一项新功能.正如在@ Psychotechnopath的回答中指出的那样,路径可能存在一些问题,因此Pycharm在Traceback中的Pycharm脚本调用时无法找到切换后端模块.
但是,我不认为手动添加任何东西到路径是一个理想和强大的解决方案.相反,我使用Anaconda Prompt中的conda安装程序将matplotlib降级到版本2.2.3:
conda install matplotlib=2.2.3
Run Code Online (Sandbox Code Playgroud)
在降级之后,我能够再次在Pycharm中导入matplotlib而没有任何问题.