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

Jupyter Notebook环境下plotly报错找不到已安装的符合要求的nbformat

已验证nbformat版本符合要求但plotly绘图仍报缺失nbformat错误的解决方案

问题原因

你在自行编写的断言中校验的是当前Python内核环境下可直接导入的nbformat版本,但plotly的渲染逻辑在模块初始化阶段就已经完成了nbformat的导入并将结果存储在内部变量中,若初始化时导入失败或拿到了旧版本,后续你自行导入的正确版本不会同步更新到plotly的内部变量中,因此会出现断言校验通过但调用fig.show()仍报错的矛盾情况。

可行解决方案

  • 方案1:手动替换plotly内部的nbformat引用
    在调用fig.show()前加入以下代码,直接将plotly渲染模块的nbformat变量替换为你已经校验过版本的实例:
import nbformat
from plotly.io import _renderers
_renderers.nbformat = nbformat
  • 方案2:手动指定plotly渲染器
    绕过需要依赖nbformat的默认mime渲染逻辑,手动指定适配Jupyter环境的渲染器:
import plotly.io as pio
# 经典Jupyter Notebook使用该配置
pio.renderers.default = "notebook"
# 若使用JupyterLab可替换为:pio.renderers.default = "jupyterlab"
# 以上配置都失效可尝试用iframe渲染:pio.renderers.default = "iframe"
  • 方案3:清理缓存重装nbformat
    执行以下命令完全卸载重装nbformat后重启Jupyter内核,清除旧的模块导入缓存:
pip uninstall -y nbformat
pip install "nbformat>=4.2.0"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 20:45:02