## TL;DR

Install it into that environment (use the %pip magic inside a cell so it lands in the kernel's env, not the server's) and restart the kernel. - Control comm was closed too early` right after a kernel restart is expected: widget state lives in the kernel process, so outputs created before the restart cannot be revived. Restart the kernel and re-run the widget cells (new Python widget state).

## When to use

You are seeing this: The output area shows an error box mentioning the widget renderer, or the browser console shows Could not open comm / Control comm was closed too early: the kernel side failed. Use this skill when you run into "Fix ipywidgets that render blank or fail in JupyterLab".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

Versions mentioned in the source: 5.3. If you are on something much newer or older, the details may have shifted.

Use this when a cell creating a widget (e.g. `widgets.IntSlider()`, `tqdm` notebook
bars, plotly figures rendered through ipywidgets) shows blank output, an error box,
or nothing at all. A widget has two halves, Python code in the kernel and a
JavaScript renderer in the browser, and the failure tells you which half is broken.
Classify first from the visible symptom, then fix that half.

## 1. Classify the failure from the visible symptom

**A. The output area shows an error box** mentioning the widget renderer, or the
browser console shows `Could not open comm` / `Control comm was closed too early`:
the kernel side failed. The widget's communication channel never opened or died 
usually the kernel was restarted after the widget was created, or the running
kernel doesn't have ipywidgets installed at all.

**B. The browser console shows `Cannot find model module @jupyter-widgets/controls`**
(or a similar module-not-found message): a frontend/backend version mismatch. The
Python ipywidgets in the kernel and the JupyterLab extension rendering it disagree.

**C. No error anywhere, just blank output:** usually B in disguise (mismatched
versions fail silently) or the rendering extension is missing entirely. Check
both halves anyway (steps 2 and 3).

## 2. Check the kernel half

From a cell in the running notebook:

```python
import ipywidgets
print(ipywidgets.__version__)
```

- `ImportError` / `ModuleNotFoundError`: ipywidgets is not installed in the
 kernel's environment. Install it into that environment (use the `%pip` magic
 inside a cell so it lands in the kernel's env, not the server's) and restart
 the kernel.
- `Control comm was closed too early` right after a kernel restart is expected:
 widget state lives in the kernel process, so outputs created before the restart
 cannot be revived. Re-run the cells that created the widgets; the old output
 areas will stay dead.

## 3. Check the browser half

```bash
jupyter labextension list
```

Look for a line like `@jupyter-widgets/jupyterlab-manager v5.x.x enabled OK`.
The version pairing that works (verified against the packages' own metadata):

- **ipywidgets 8.x** requires `jupyterlab_widgets~=3.0` and `widgetsnbextension~=4.0`
 (both pulled in automatically by `pip install ipywidgets`), and works with
 **JupyterLab 3.x and 4.x**. Per the jupyterlab-widgets README: "To enable
 ipywidgets support in JupyterLab 3.x or 4.x: `pip install jupyterlab_widgets`".
- **ipywidgets 7.x** pairs with **JupyterLab 2.x** via
 `jupyter labextension install @jupyter-widgets/jupyterlab-manager@2`.
 Prebuilt (pip-installable) widget extensions arrived with JupyterLab 3; older
 Labs need the manual `labextension install` with the matching major version.

If the manager line is missing, disabled, or its major version doesn't match the
Python ipywidgets major version, the browser half is broken.

## 4. Fix: resync the two halves, then restart and refresh

```bash
pip install --upgrade ipywidgets jupyterlab_widgets
# conda users: conda install -c conda-forge ipywidgets jupyterlab_widgets
```

Then do **both** of these, one without the other leaves the bug in place:

1. Restart the kernel and re-run the widget cells (new Python widget state).
2. Hard-refresh the browser page (or open a fresh tab). A newly installed
 frontend extension only takes effect in a freshly loaded page.

Classic Notebook 6.x (not JupyterLab / Notebook 7): stay on the ipywidgets 7
line and make sure the nbextension is enabled:

```bash
jupyter nbextension enable --py --sys-prefix widgetsnbextension
```

(This can be skipped for notebook version 5.3 and above, where it is enabled
automatically.)

## 5. Checklist for the broken widget

1. Reproduce and capture the exact symptom: error-box text or browser-console
 (F12) message.
2. Classify: comm error (kernel half) vs model-module error (version mismatch)
 vs blank (check both halves).
3. Kernel half: `import ipywidgets` works in the running kernel; re-run widget
 cells after every kernel restart.
4. Browser half: `@jupyter-widgets/jupyterlab-manager` present and enabled in
 `jupyter labextension list`, major version matching the Python ipywidgets.
5. Resync with the upgrade command, then restart the kernel AND refresh the page.
