Plotly ValueError: Mime type rendering requires nbformat>=4.2.0 (tested)

ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed from fig.show() means Jupyter/VS Code rendering needs the nbformat package, which pip install plotly does not pull in. Run %pip install "nbformat>=4.2.0" in the notebook, then restart the kernel: installing it into a running kernel is not enough.

1. Reproduce it

b2.py (outside Jupyter we replace IPython.display.display with a stub that prints which MIME types would be sent to the notebook, instead of dumping the whole figure):

import IPython.display
# outside Jupyter, print which MIME bundle would be sent instead of dumping it
IPython.display.display = lambda obj, raw=False, **kw: print("  displayed:", sorted(obj))
import plotly.express as px
fig = px.line(x=[1, 2, 3], y=[4, 1, 6])
for r in ["plotly_mimetype", "vscode", "colab"]:
    try:
        fig.show(renderer=r)
        print(f"{r}: OK")
    except ValueError as ex:
        print(f"{r}: ValueError: {ex}")

Fresh venv, plotly 7.1.0, ipython 9.17.1, Python 3.13.5:

$ pip install -q plotly pandas ipython
$ python b2.py
plotly_mimetype: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed
vscode: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed
colab: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed
$ pip install -q "nbformat>=4.2.0"
$ python b2.py
  displayed: ['application/vnd.plotly.v1+json']
plotly_mimetype: OK
  displayed: ['application/vnd.plotly.v1+json']
vscode: OK
  displayed: ['text/html']
colab: OK

2. Installed nbformat and it still fails? Restart the kernel

b4.py installs nbformat into its own environment while running:

import IPython.display, subprocess, sys
IPython.display.display = lambda obj, raw=False, **kw: print("  displayed:", sorted(obj))
import plotly.express as px
fig = px.line(x=[1, 2, 3], y=[4, 1, 6])
def show():
    try:
        fig.show(renderer="plotly_mimetype"); print("show: OK")
    except ValueError as ex:
        print("show: ValueError:", ex)
show()
subprocess.run([sys.executable, "-m", "pip", "install", "-q", "nbformat>=4.2.0"], check=True)
print("installed nbformat in the running process's environment")
show()
show: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed
installed nbformat in the running process's environment
show: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed

3. Without nbformat: write_html works, iframe/json do not

import IPython.display
IPython.display.display = lambda obj, raw=False, **kw: print("  displayed:", sorted(obj) if isinstance(obj, dict) else type(obj).__name__)
import plotly.express as px, plotly.io as pio, os
fig = px.line(x=[1, 2, 3], y=[4, 1, 6])
fig.write_html("fig.html")
print("write_html: OK,", os.path.getsize("fig.html") // 1024, "KiB")
for r in ["iframe", "json"]:
    try:
        fig.show(renderer=r)
        print(f"{r}: OK")
    except ValueError as ex:
        print(f"{r}: ValueError: {ex}")
write_html: OK, 4710 KiB
iframe: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed
json: ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed

Frequently asked questions

How do I fix Mime type rendering requires nbformat>=4.2.0?

Run %pip install "nbformat>=4.2.0" in the notebook, then restart the kernel and re-run the cell.

I installed nbformat but plotly still shows the error. Why?

The kernel was not restarted, or nbformat went into a different environment than the kernel uses (check sys.executable).

Can I show a plotly figure without nbformat?

Yes, with fig.write_html("fig.html") and opening the file in a browser. The iframe and json renderers still need nbformat.

Written with AI assistance. Measured on 2026-10-23 with plotly 7.1.0, ipython 9.17.1, nbformat 5.11.1 and Python 3.13.5 on Linux. Scripts ran verbatim and the output was pasted unedited. PlainTables is our extension; Plotly is free.