Jupyter执行Matplotlib相关代码时内核被终止问题求助
- 先排查安装损坏问题:激活你当前使用的Python虚拟环境,执行
pip uninstall matplotlib完成卸载后,再执行pip install matplotlib重新安装。如果使用conda管理环境,替换为conda install matplotlib即可。 - 调整matplotlib后端配置:%matplotlib inline指定的渲染后端和本地环境冲突是常见诱因,可以调整代码顺序先指定后端再导入pyplot,修改后代码如下:
%matplotlib inline import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt
- 重启Jupyter服务:如果仅重启内核无效,可以直接关闭运行Jupyter的终端进程,重新启动Jupyter后再运行代码尝试。
- 兼容版本安装:如果上述操作都无效,大概率是版本兼容问题,可以安装稳定适配的3.7.3版本,执行命令
pip install matplotlib==3.7.3即可。
内容的提问来源于stack exchange,提问作者Carlos Ortiz
相关产品推荐
相关产品推荐

