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

如何解决Jupyter Notebook交互式绘图时的"Javascript Error: IPython is not defined"错误

解决Jupyter Notebook中%matplotlib notebook的"IPython is not defined"错误

问题根源

更新Anaconda后,matplotlib的notebook交互式后端与新版Jupyter的前端组件(如ipywidgets)版本不兼容,导致前端无法识别IPython对象。

可行解决方案

  • 降级matplotlib到兼容版本
    打开Anaconda Prompt(或终端)执行:

    conda install matplotlib=3.5.3
    

    该版本与新版Jupyter环境兼容性良好,能避免前端交互报错。

  • 替换为%matplotlib widget后端
    无需降级,直接改用更适配新版环境的交互式后端,修改代码如下:

    import matplotlib.pyplot as plt
    %matplotlib widget  # 替换原%matplotlib notebook
    plt.figure()
    plt.plot(x, y)
    plt.show()
    

    widget后端是notebook的替代方案,交互功能一致且稳定性更高。

  • 重置Jupyter前端配置
    若前两种方法无效,重置Jupyter的前端静态文件:

    jupyter nbextension enable --py widgetsnbextension
    jupyter nbextension install --py widgetsnbextension --user
    

    执行完成后重启Jupyter Notebook即可。

内容的提问来源于stack exchange,提问作者Somnath Jana

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 23:42:10