AntMan
AntMan

Reputation: 1753

Javascript Error: IPython is not defined in JupyterLab

I have the latest/updated Anaconda package. Everytime I try to plot something using python 3.6.6 I get the following error in JupyterLab...

Javascript Error: IPython is not defined

When I run the same code in Spyder using an ipython kernel, it works just fine. Have been looking all over online but cant seem to figure out what is going on. Any help would be appreciated.

Upvotes: 175

Views: 278294

Answers (9)

Harsh Bopaliya
Harsh Bopaliya

Reputation: 11

just remove %matplotlib notebook because in Jupyter notebook this line give error. when i run some code i get same error "Javascript Error: IPython is not defined in JupyterLab" but when i just see one things in my code i write %matplotlib notebook that is use in colab notebook not in jupyter notebook

Upvotes: 1

Juan I.
Juan I.

Reputation: 11

After installing ipympl, then reinstalling jupyter-lab the way to get it to work was by importing like:

%matplotlib ipyml

Upvotes: -1

Fyind
Fyind

Reputation: 1

Install Anaconda and start notebook from anaconda navigator. It resolves my problem.(The solution above didn't work for me. )

Upvotes: -1

TomNorway
TomNorway

Reputation: 3162

Jupyter Lab does support interactive matplotlib through the jupyter-matplotlib extension. The installation procedure is slightly more involved, but works fine. Since the ipympl Jupyter Lab version requires NodeJS, and NodeJS requires Windows 8.1, ipympl also has this requirement.

As before, it is important to invoke the iPython magic command before plotting:

Usage:

%matplotlib widget

Installation:

Note: If using this extension with Jupyter Lab, it's recommended to use a version >= 3. For more detailed instructions on installing an old extension than below, see the instructions on ipympl github.

Using conda

conda install -c conda-forge ipympl

# If using JupyterLab 2
conda install nodejs
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter lab build

# Later, if updating a previous Lab install:
conda install ipympl
jupyter lab build

Using pip

pip install ipympl

# If using JupyterLab 2
pip install nodejs-bin
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install jupyter-matplotlib

Upvotes: 142

palhares
palhares

Reputation: 1823

Jupyter Lab does support interactive matplotlib through the jupyter-matplotlib extension. See TomNorway's answer.

Alternatively, you can configure matplotlib to use inline instead. inline is not as powerful as interactive, but it can save you.

To use inline, add this line before plot the graph:

    %matplotlib inline

More Info

Upvotes: 91

user17557081
user17557081

Reputation: 127

Encountered similar issue when using backtrader. This fixed it for me:

cerebro.plot(iplot = False)

Upvotes: 11

Keivan
Keivan

Reputation: 1781

I could solve the same problem by installing ipympl:

pip install ipympl

And then add %matplotlib ipympl before plot.

Upvotes: 9

burhan rashid
burhan rashid

Reputation: 450

I was getting Ipython not defined in jupyter notebook when I tried to display a html formated content in my jupyter notebook, I just imported the function and it worked

from IPython.core.display import display, HTML # my imports

annot = coco_dataset.display_image(21, use_url=False) #my function return a html page

HTML(annot) # used for displaying the page

Upvotes: -1

Ulysses
Ulysses

Reputation: 161

  1. Jupyterlab supports jpympl.

  2. You must put %matplotlib widget in the very beginning of the jupyterlab.

You can change to %matplotlib inline in specific cell, and active %matplotlib widget again if needed.

Otherwise, no matter how many times you reinstall the package, you will still get the errors.

Upvotes: 6

Related Questions