In a Jupyter notebook browser tab, the console may show:
Javascript Error: IPython is not definedThat message usually means the notebook front end and your Matplotlib backend do not match. It does not normally mean the Python IPython package is missing from the kernel.
A common trigger is the legacy magic:
%matplotlib notebookOn Jupyter Notebook 7, JupyterLab, VS Code notebooks, or Google Colab, switch to a supported backend instead:
%matplotlib widgetOn Jupyter Notebook 7, JupyterLab, or VS Code, install
ipympland use%matplotlib widgetor%matplotlib ipympl. In Google Colab, also enable the custom widget manager. Use%matplotlib inlinewhen interactive controls are unnecessary.
Tested on: Rocky Linux 10.2; Python 3.12.13; Jupyter Notebook 7.6.0; JupyterLab 4.6.1; Matplotlib 3.11.0; ipympl 0.10.0.
Which fix to use
Pick the row that matches your notebook environment or symptom. Each link jumps to the fix section for that case. If you are not sure which Jupyter front end you are running, start with Check your Jupyter environment and versions.
| Your situation | What to do | Go to |
|---|---|---|
| Jupyter Notebook 7, JupyterLab, or VS Code; you want interactive plots | Install ipympl, restart the kernel, run %matplotlib widget |
Fix 1: Use ipympl in Notebook 7 or JupyterLab |
| You only need a static plot image in the cell output | Switch to %matplotlib inline |
Fix 2: Use %matplotlib inline for static plots |
pip install ipympl worked in a terminal but the notebook still fails |
The kernel or Jupyter server may be using a different Python environment | Fix 3: Resolve kernel and package environment mismatches |
VS Code .ipynb notebook |
Confirm extensions, kernel, ipympl, and backend magic |
Fix 4: VS Code notebooks and Google Colab |
| Google Colab runtime | Install ipympl and enable the custom widget manager |
Fix 4: VS Code notebooks and Google Colab |
Notebook or extension calls IPython.notebook in JavaScript |
Update the extension or replace classic front-end APIs | Fix 5: Old notebook extensions or JavaScript code |
Old teaching notebook must keep %matplotlib notebook |
Treat nbclassic as a compatibility path |
Use nbclassic only for legacy notebooks |
ModuleNotFoundError: No module named 'ipympl' |
Install ipympl into the active kernel, not just the terminal |
Fix 1: Use ipympl in Notebook 7 or JupyterLab |
%matplotlib widget is set but the error or blank plot remains |
Work through the backend and environment checklist | Troubleshoot when %matplotlib widget still fails |
Choose the correct Matplotlib backend
| Notebook environment | Recommended backend | Additional package |
|---|---|---|
| Jupyter Notebook 7 or newer | %matplotlib widget or %matplotlib ipympl |
ipympl |
| JupyterLab | %matplotlib widget or %matplotlib ipympl |
ipympl |
| VS Code notebook | %matplotlib widget or %matplotlib ipympl |
ipympl |
| Google Colab | %matplotlib widget with widget manager enabled |
ipympl |
| Static plots in any notebook | %matplotlib inline |
None |
| Classic Notebook below version 7 | %matplotlib notebook or %matplotlib nbagg |
None |
nbclassic |
%matplotlib notebook can still work |
None |
%matplotlib notebook turns on the older nbAgg backend. %matplotlib widget and %matplotlib ipympl activate the modern ipympl backend.
Official compatibility summary:
| Backend | Supported front ends |
|---|---|
ipympl |
JupyterLab and Jupyter Notebook 7 or newer, VS Code notebooks, Google Colab |
nbAgg |
Classic Notebook below version 7 and nbclassic |
Why “IPython is not defined” appears
Three different ideas are easy to mix up:
| Name | What it is |
|---|---|
Python IPython package |
Python library used by the notebook kernel |
| Notebook kernel | Python process executing your cells |
Browser IPython global |
JavaScript object exposed by classic Notebook front ends |
Interactive Matplotlib modes and some extensions call JavaScript such as IPython.notebook.kernel. Jupyter Notebook 7 and JupyterLab do not expose that global the same way classic Notebook did. The browser then reports IPython is not defined even when Python cells run normally.
Installing IPython with pip does not fix that mismatch when the kernel already executes code successfully.
A common failing cell sequence looks like this:
%matplotlib notebook
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()In Notebook 7 or JupyterLab, %matplotlib notebook targets the legacy nbAgg path. The front end no longer provides the JavaScript IPython object that backend expects, so the plot step fails in the browser.
Check your Jupyter environment and versions
A Jupyter deployment can use separate environments for the browser front end and Jupyter server, the Python kernel, a remote JupyterHub or hosted server, and the local VS Code application. Check the front-end version from the Jupyter interface or from the environment that launches the Jupyter server—not by inferring it from kernel-side packages.
From a terminal on the machine or environment that runs the Jupyter server, list the installed server and front-end packages:
jupyter --versionSample output:
Selected Jupyter core packages...
IPython : 9.15.0
ipykernel : 7.3.0
ipywidgets : 8.1.8
jupyter_client : 8.9.1
jupyter_core : 5.9.1
jupyter_server : 2.20.0
jupyterlab : 4.6.1
nbclient : 0.11.0
nbconvert : 7.17.1
nbformat : 5.10.4
notebook : 7.6.0
traitlets : 5.15.1jupyter --version from the server environment identifies installed server and front-end packages. It does not prove which interface your current browser tab is using. Notebook 7 and nbclassic can coexist on the same Jupyter Server, so an installed notebook 7.x package does not by itself confirm that the open tab is the Notebook 7 front end. Confirm the active interface from the Jupyter UI—Help menu, About dialog, or the URL you opened (/lab, /tree, nbclassic, VS Code, or Colab).
Inside the affected notebook, check the active Python interpreter and Matplotlib backend:
import sys
import matplotlib
print("Python:", sys.executable)
print("Matplotlib:", matplotlib.__version__)
print("Backend:", matplotlib.get_backend())Sample output from a normal Jupyter notebook before you change backends:
Python: /usr/bin/python3
Matplotlib: 3.11.0
Backend: inlineDepending on Matplotlib and matplotlib-inline versions, the backend may instead appear as a module path such as module://matplotlib_inline.backend_inline.
A standalone Python process without a graphical display may report agg. Inside a normal Jupyter notebook, the initial backend is usually the static inline backend. After %matplotlib widget, the reported backend should identify the ipympl or widget backend.
Inspect kernel-side plotting packages with %pip in the notebook:
%pip show matplotlib ipympl ipywidgetsUse that output to confirm:
ipymplis missing from the kernel → install it before using%matplotlib widget- the kernel’s Python path matches the environment where you expected packages to be installed
- in VS Code, the selected kernel matches the environment shown by
sys.executablein the notebook - in JupyterHub or other remote-kernel deployments, the server and kernel may use different environments—
%pip showdescribes only the kernel side
Fix 1: Use ipympl in Notebook 7 or JupyterLab
Install ipympl in the active notebook kernel:
%pip install ipymplFor Conda environments:
%conda install -c conda-forge ipymplWhen installing from a terminal instead, target the same interpreter the notebook kernel uses:
python -m pip install ipymplRestart the kernel after installation. Restart JupyterLab or Notebook if the front end still shows the old error.
Activate the backend before importing pyplot:
%matplotlib widget%matplotlib ipympl activates the same backend.
Test with a minimal plot:
%matplotlib widget
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9])
ax.set_title("Interactive Matplotlib test")
plt.show()On current JupyterLab and Notebook 7 releases, installing ipympl in the kernel is usually enough when the server and kernel share one environment. You do not need legacy commands such as jupyter labextension install @jupyter-widgets/jupyterlab-manager unless you are on JupyterLab below version 3.
When the Jupyter server and notebook kernel use separate environments, installing ipympl only in the kernel may not be sufficient. ipympl includes both a Python backend that runs in the kernel and a JavaScript front-end component used by the notebook interface. In JupyterHub, remote-kernel, or other split deployments, confirm that the server environment provides a compatible jupyter-matplotlib front-end extension and that its version matches the kernel-side ipympl package. The official ipympl installation guide documents this front-end and back-end split and publishes a compatibility table.
Fix 2: Use %matplotlib inline for static plots
When pan, zoom, and toolbar controls are unnecessary, use the inline backend:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.show()This renders a static image in the cell output and avoids the interactive widget front end entirely. That is a valid choice when you only need the plot displayed, not a workaround for broken interactivity. For broader Matplotlib plotting patterns in Python, see the Python Matplotlib guide.
Fix 3: Resolve kernel and package environment mismatches
ipympl may install successfully into a different Conda environment, virtual environment, or system Python than the one your notebook kernel uses. The same problem appears when the Jupyter server environment and the kernel environment are different: a terminal install or jupyter --version check on the server host does not automatically update the kernel where %matplotlib widget runs.
Compare the kernel path from the notebook:
import sys
print(sys.executable)With the terminal Python on the same machine:
python -c "import sys; print(sys.executable)"When both lines print the same path, the kernel and terminal share one interpreter.
Verify that ipympl imports inside the notebook:
import ipympl
print(ipympl.__version__)Sample output after a successful install:
0.10.0Recommended recovery steps:
- Select the correct notebook kernel in the UI.
- Install
ipymplwith%pipor%condafrom that kernel. - Restart the kernel.
- Reload the notebook front end.
- Run the backend magic before creating any figures.
Repeatedly running pip install IPython does not fix an environment mismatch when Python cells already execute and only the browser reports IPython is not defined.
Fix 4: VS Code notebooks and Google Colab
VS Code notebooks
Confirm that:
- the Microsoft Python and Jupyter extensions are enabled
- the correct Python kernel or environment is selected from the notebook kernel selector for the
.ipynbfile ipymplis installed in that kernel- the notebook uses
%matplotlib widget, not%matplotlib notebook - VS Code is reloaded after installing or updating notebook packages
Run the same minimal interactive test plot from Fix 1 after changing the backend.
Google Colab
Install the backend in the runtime:
%pip install ipymplEnable Colab’s custom widget manager:
from google.colab import output
output.enable_custom_widget_manager()Then activate the widget backend:
%matplotlib widgetRestart the Colab runtime if widgets still fail to render after installation.
Fix 5: Old notebook extensions or JavaScript code
Some notebooks or extensions still contain JavaScript like:
IPython.notebook.kernel.execute("print('Hello')");That API belongs to classic Notebook JavaScript and is not portable to JupyterLab or Notebook 7.
Recommended actions:
- Update the package or notebook extension.
- Check for a Notebook 7 or JupyterLab-compatible release.
- Replace direct front-end access with supported widgets, comms, or a JupyterLab extension.
- Contact the package maintainer when the JavaScript is generated by a third-party Python library.
Do not define a fake global IPython object in the browser to silence the error.
Legacy JupyterLab 1 and 2 extension commands
JupyterLab versions below 3 required building the widget extensions manually:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install jupyter-matplotlibJupyterLab 3 and 4 normally use the prebuilt extension installed with ipympl; do not run these legacy Node.js build commands in the modern default workflow. The official ipympl installation guide places these commands under JupyterLab below version 3.
Use nbclassic only for legacy notebooks
nbclassic may be appropriate when:
- an old teaching notebook depends on
%matplotlib notebook - a critical extension has no Notebook 7-compatible version
- custom JavaScript depends on classic Notebook APIs
Treat it as a compatibility path, not the primary modern solution.
Downgrading to notebook<7 can reproduce classic behaviour, but migrating to ipympl or a supported extension is the better long-term fix.
Troubleshoot when %matplotlib widget still fails
| Symptom | Likely cause | Action |
|---|
| Step | Check |
|---|---|
| 1 | Confirm import ipympl succeeds in the active kernel |
| 2 | Restart the kernel after installation |
| 3 | Restart JupyterLab, Notebook, VS Code, or the Colab runtime |
| 4 | Run the backend magic before the first figure |
| 5 | Do not switch between notebook, inline, and widget repeatedly in one kernel |
| 6 | Inspect matplotlib.get_backend() |
| 7 | Confirm compatible Matplotlib, ipympl, JupyterLab, and widget versions—the tested combination here (ipympl 0.10.0, JupyterLab 4.6.1, Matplotlib 3.11.0) is within the current official compatibility range |
| 8 | Test a clean notebook with only the minimal plot |
| 9 | Disable outdated notebook extensions when the clean notebook works |
| 10 | Review browser-console errors only after backend and environment checks |
Related error: ModuleNotFoundError: No module named 'ipympl'
ModuleNotFoundError: No module named 'ipympl'That means the Python package is missing from the current kernel. Install ipympl with %pip install ipympl in the notebook, restart the kernel, and run %matplotlib widget again. It is a different failure mode from the browser-side IPython is not defined message.
Common mistakes to avoid
- Installing
IPythonwithout checking the Matplotlib backend - Copying JupyterLab 1 or 2 extension-build commands into JupyterLab 3 or 4
- Installing packages in the terminal without checking which kernel—or Jupyter server environment—the notebook uses
- Continuing to use
%matplotlib notebookin Notebook 7 - Downgrading the complete Jupyter environment before trying
ipympl - Mixing multiple Matplotlib backends in one kernel session
- Assuming every
IPython is not definederror comes from Matplotlib; some originate in old third-party JavaScript
Summary
- Use
%matplotlib inlinefor static output. - Use
ipymplwith%matplotlib widgetor%matplotlib ipymplfor modern interactive notebooks. - Use
%matplotlib notebookonly with classic Notebook below version 7 ornbclassic. - Check the active kernel and, in split deployments, the server-side
jupyter-matplotlibextension when installation appears successful but the error continues. - Update old extensions that access
IPython.notebookdirectly.
References
- Matplotlib Jupyter Integration (ipympl)
- ipympl installation and compatibility
- matplotlib/ipympl on GitHub
- IPython documentation
- Jupyter Notebook documentation
