Matplotlib 报错 AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘

解决办法一

在代码开始的部分添加引用

import matplotlib
matplotlib.use('TkAgg')

解决办法二

降低 matplotlib 的版本,3.5.0版本及以下的都可以

pip install matplotlib==3.5.0

官方文档指出:

如果没有显式设置后端,Matplotlib 会根据系统上可用的内容以及是否已运行 GUI 事件循环自动检测可用的后端。选择以下列表中第一个可用的后端:MacOSX、QtAgg、GTK4Agg、Gtk3Agg、TkAgg、WxAgg、Agg。最后一个 Agg 是一个非交互式后端,只能写入文件。如果 Matplotlib 无法连接到 X 显示或 Wayland 显示,则在 Linux 上使用它。

什么是后端?

后端用于显示 Matplotlib 图形(请参阅 图形简介),在屏幕上或写入文件。

官方地址

你可能感兴趣的:(Matplotlib 报错 AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘)