Matplotlib报错AttributeError: module 'matplotlib.cbook' has no attribute '_Stack'求助
解决Matplotlib版本冲突引发的
AttributeError: module 'matplotlib.cbook' has no attribute '_Stack'问题 1. 彻底清理环境中的Matplotlib相关包
先激活你的conda环境(把your_env换成实际环境名称):
conda activate your_env
接着卸载所有Matplotlib相关包:
pip uninstall -y matplotlib conda uninstall -y matplotlib matplotlib-base
检查是否清理干净,执行以下命令确认无残留:
pip list | grep matplotlib conda list | grep matplotlib
如果还有残留,用pip show matplotlib查看安装路径,手动删除对应文件夹。
2. 用conda重新安装匹配版本的Matplotlib
保持环境激活状态,执行安装命令:
conda install matplotlib
conda会自动安装配套的matplotlib和matplotlib-base,确保版本兼容。
3. 验证修复效果
打开Python终端测试:
import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.show()
能正常弹出绘图窗口就说明问题解决了。
注意事项
- 别在conda环境里混用pip和conda装Matplotlib这类依赖复杂的库,很容易搞出版本冲突。
- 要是需要用Seaborn,直接用
conda install seaborn安装,它会自动匹配兼容的Matplotlib版本。
内容的提问来源于stack exchange,提问作者Nora
相关产品推荐
相关产品推荐

