You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下Emacs搭配matplotlib绘图出现卡死问题的可行解决方案

Windows10下Emacs搭配matplotlib绘图卡死问题解决方案

问题说明

在Windows10系统中使用Emacs搭配matplotlib库绘制图表时,会出现两类异常问题:

  • 无法生成图表,且Python缓冲区直接卡死
  • 可正常弹出图表,但后续操作依然会触发卡死
    经测试各类公开方案均无法解决该问题,下述为亲测有效的修复方案。

修复步骤

  1. 安装依赖包
    执行以下命令完成基础依赖安装:
pip install ipython
pip install matplotlib
  1. 配置Emacs Python解释器
    在Emacs的init.el配置文件中添加如下代码,指定使用ipython作为Python shell的解释器:
(when (executable-find "ipython")
  (setq python-shell-interpreter "ipython"))
  1. 配置matplotlib后端
    启动Emacs后执行M-x run-python命令运行ipython环境,依次执行以下操作确认后端配置:
  • 执行import matplotlib加载matplotlib库
  • 调用matplotlib.get_backend()接口,确认当前使用的后端为TkAgg,经测试Qt系列后端在该场景下无法正常运行
  • 若当前后端不符合要求,在matplotlibrc配置文件中添加一行backend : TkAgg即可

效果验证

配置完成后运行如下测试脚本,可正常生成图表且不会出现卡死问题:

matplotlib.get_backend()
import matplotlib.pyplot as plt
plt.ioff()
plt.plot([1,2,3,4])
plt.show()
print("Test")

内容的提问来源于stack exchange,提问作者Newb'R

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 01:15:04