在PyCharm中使用matplotlib出现错误:'没有'FigureCanvas'属性。
在PyCharm中使用matplotlib出现错误:'没有'FigureCanvas'属性。
这个问题已经有了答案:
如何处理\"ImportError: 无法导入名称X\"或\"AttributeError:...(很可能是由于循环导入)\"?
我有这段代码:
import matplotlib.pyplot as p1lt #define data x = [1, 2, 3, 4, 5, 6] y = [3, 7, 14, 19, 15, 11] #create line plot p1lt.plot(x, y) #show line plot p1lt.show()
我得到了一个错误,显示如下:
Matplotlib support failed Traceback (most recent call last): File "C:\Users\G\AppData\Roaming\JetBrains\IdeaIC2022.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 25, in do_import succeeded = activate_func() File "C:\Users\G\AppData\Roaming\JetBrains\IdeaIC2022.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_code_executor.py", line 29, in "matplotlib": lambda: activate_matplotlib(self.enableGui), File "C:\Users\G\AppData\Roaming\JetBrains\IdeaIC2022.2\plugins\python-ce\helpers\pydev\pydev_ipython\matplotlibtools.py", line 110, in activate_matplotlib gui, backend = find_gui_and_backend() File "C:\Users\G\AppData\Roaming\JetBrains\IdeaIC2022.2\plugins\python-ce\helpers\pydev\pydev_ipython\matplotlibtools.py", line 47, in find_gui_and_backend backend = matplotlib.rcParams['backend'] File "D:\books\programming\python17\lib\site-packages\matplotlib\__init__.py", line 677, in __getitem__ plt.switch_backend(rcsetup._auto_backend_sentinel) File "D:\books\programming\python17\lib\site-packages\matplotlib\pyplot.py", line 251, in switch_backend switch_backend(candidate) File "D:\books\programming\python17\lib\site-packages\matplotlib\pyplot.py", line 266, in switch_backend canvas_class = backend_mod.FigureCanvas AttributeError: partially initialized module 'matplotlib.backends.backend_macosx' has no attribute 'FigureCanvas' (most likely due to a circular import) Process finished with exit code 0
我以前在我的电脑上使用过Matplotlib,我将Python和IntelliJ删除并重新安装。
错在哪里?我该怎么修复?
admin 更改状态以发布 2023年5月21日