Searches such as javascript error: ipython is not defined, javascript error ipython is not defined, or simply ipython is not defined almost always point to the same situation: a notebook cell ran plotting or widget code that expects a browser global named IPython, but the front end that loaded your notebook page does not expose it. The message is raised from the notebook’s JavaScript context, not from the Python interpreter printing a normal traceback, which is why it is filed mentally under “javascript error” even though the fix is usually on the Python or Jupyter configuration side.
You will see the same underlying problem when people combine queries with matplotlib notebook, jupyter notebook javascript error, or VS Code’s notebook UI. The fix is to align the matplotlib backend with what your Jupyter front end actually supports, then restart the kernel.
Tested on: Node.js v20.18.2 for the one-line
typeofcheck below. Jupyter steps are configuration guidance (reproduce in your notebook UI).
In a normal Node process there is no Jupyter injection, which mirrors “global missing” failures:
console.log(typeof globalThis.IPython);You should see one line: undefined.
Common magics people compare in docs and forums:
%matplotlib inline— static figures in the output cell%matplotlib widget— interactive backend (with ipympl installed)%matplotlib ipympl— alias depending on docs version
What “JavaScript Error: IPython is not defined” means
Interactive matplotlib modes and some notebook extensions assume a browser environment where IPython exists so they can call IPython.notebook.kernel and similar APIs. When that object is missing—wrong URL (file:// instead of served notebook), broken extension bundle, blocked script, or a backend that never registered the shim—the browser console reports javascript error ipython is not defined or, on WebKit, “can’t find variable: ipython”. The Python side may still be running; the UI layer is what failed.
Why it clusters with %matplotlib notebook and matplotlib notebook mode
Historically, %matplotlib notebook turned on the interactive “nbagg” style experience inside classic Jupyter Notebook. That stack depended heavily on notebook JavaScript. In current Jupyter Notebook 7 (built on JupyterLab components) and in many VS Code setups, the old assumptions no longer line up one‑to‑one, so searches like matplotlib notebook ipython is not defined or jupyter notebook 7 %matplotlib notebook ipython is not defined are common.
Practical approach today:
- Prefer
%matplotlib inlinewhen you only need static images in the output cell. - Prefer the maintained interactive path: install
ipympland use%matplotlib widget(or%matplotlib ipympl, depending on your docs) so the widget machinery matches modern Jupyter.
Quick fix: static plots (%matplotlib inline)
If you do not need pan/zoom, put this once per session (near the top, before importing pyplot) and restart the kernel:
%matplotlib inlineThen re‑run cells. Static png/svg renders avoid the browser IPython bridge entirely, which clears javascript error ipython is not defined jupyter notebook style failures for many teaching notebooks.
Interactive plots: ipympl and %matplotlib widget
When you truly need interaction, install the Jupyter integration package and switch the magic:
pip install ipymplor, with Conda:
conda install -c conda-forge ipymplEnable the widget backend:
%matplotlib widgetFollow the current ipympl documentation for JupyterLab extension steps for your major version. After installing extensions, restart JupyterLab or VS Code completely so the new JavaScript assets load.
JupyterLab and older extension stacks
On older JupyterLab releases you sometimes needed Node.js present to build extensions, and you installed helpers such as @jupyter-widgets/jupyterlab-manager together with jupyter-matplotlib. Newer JupyterLab versions manage extensions differently; still, if you are on an older lab, match the versions described in the ipympl repository rather than copying decade‑old shell snippets blindly.
VS Code notebooks (vscode %matplotlib notebook ipython is not defined)
In VS Code, confirm:
- The Microsoft Jupyter extension is installed and enabled.
- You opened a
.ipynbas a notebook, not only as raw JSON text. - A Python interpreter with
matplotlib(andipymplif interactive) is selected as the kernel. - After changing backends or extensions, run “Developer: Reload Window” once.
The VS Code webview still expects the same matplotlib backend contracts; mixing legacy %matplotlib notebook with a modern kernel is a frequent trigger for jupyter javascript error: ipython is not defined style messages.
Verification checklist after any change
- Restart the kernel (Kernel → Restart).
- Run magics before
import matplotlib.pyplot as plt. - Hard refresh the browser tab (or reload VS Code) so cached notebook JS is cleared.
- Watch the browser developer console: the error should disappear once the backend matches the environment.
Common questions in plain sections
Why do people mention %matplotlib notebook next to this error?
Because that mode was the classic interactive path in older notebooks and many Stack Overflow answers still show it. On modern Jupyter you should migrate to ipympl + %matplotlib widget or fall back to %matplotlib inline for reliability.
Is this the same as “ipython not defined” without “JavaScript”?
Yes. Different consoles phrase the missing global differently; the remediation path is the same.
Summary
Align the matplotlib backend with the front end, restart the kernel and reload the UI, and treat IPython missing as a notebook JS context problem—not a silent Python failure.
Treat javascript error ipython is not defined as a browser-side signal that notebook JavaScript expected the IPython global and never received it—often because of backend / URL / extension mismatch, not a broken Python install.
When you need interactive figures on modern Jupyter, prefer %matplotlib widget with ipympl where supported, and fall back to %matplotlib inline for static renders when the widget stack is unavailable. Keep JupyterLab, Notebook 7, VS Code, and extension versions aligned with the ipympl documentation instead of copying decade-old shell snippets verbatim.
