1

I'm trying to run a jupyter notebook featuring interactive ipywidgets using a new laptop with a new installation of jupyter/ anaconda, but consistently get the error 'Javascript Error: IPython is not defined', e.g. when running the following:

%matplotlib nbagg
import matplotlib.pyplot as plt
fig, ax = plt.subplots()

I've tried installing Anaconda navigator, and after the above was unsuccessful tried using conda to install ipython and ipympl, but still got the 'IPython is not defined' error.

Currently, starting with Miniconda3 py313_25.3.1.1, I've tried

pip install notebook
conda install matplotlib
conda install ipython
conda install ipympl

(all in the default base environment) I then restarted my PC, and when I try ipython --version in the terminal I get 8.30.3 but still get the `IPython is not defined' error in the jupyter notebook.

In the jupyter notebook, I'm using the Python 3 (ipykernel) Kernel.

4
  • 2
    always put full error message because there are other useful information. Commented Jun 22 at 15:44
  • maybe you should install it in console using pip install ipython instead of conda, or maybe in notebook run !pip install ipython and it should install it in Python which you use. Commented Jun 22 at 15:46
  • Please recommend current best practice %pip install` use and not the exclamation point in conjunction with install commands. Plus see my note about fully propagating changes as a comment to the offered answer. Commented Jun 22 at 18:27
  • In jupyter notebook 7, running %pip install ipython did enable graphs to be displayed for the first time with %matplotlib widget (but not the deprecated nbagg ). Also, the original full error message was simply 'Javascript Error: IPython is not defined' in a pink box in jupyter notebook 7 so unfortunately it wasn't providing any further information. Commented Jun 22 at 18:45

1 Answer 1

1

Reactive base environment


conda activate base

Ensure extensions work

jupyter nbextension enable --py widgetsnbextension
jupyter nbextension enable --py ipympl

restart your PC.

re-run

jupyter notebook

In notebook, Kernel --> restart and clear ouput, Run all cells.

Sign up to request clarification or add additional context in comments.

3 Comments

Pro-tip: occasionally with ipympl extension and some others. like ipywidgets, in addition to restarting the kernel, your computer, and your browser, you may need to do a hard browser refresh on the page with the code code that uses ipympl or ipywidgets. (On a mac in Chrome, it is Command + Shift + R. Supposedly in Windows it is Ctrl+Shift+R or Ctrl+F5. .) These extensions have a lot of things that involve javascript and browser connections that need to get propagated fully to work fully even after you install.
Also, the enabling of extensions shouldn't be needed in modern Jupyter if you install correctly.
This worked - previously I'd omitted the conda activate base line when trying to run jupyter nbextension enable --py widgetsnbextension and getting errors related to jupyter-nbextension not found, but I don't get that error any more after activating the base venv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.