Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript Error: IPython is not defined #7115

Closed
qci-amos opened this issue Oct 19, 2023 · 12 comments
Closed

Javascript Error: IPython is not defined #7115

qci-amos opened this issue Oct 19, 2023 · 12 comments
Labels
bug status:Needs Triage Applied to issues that need triage

Comments

@qci-amos
Copy link

qci-amos commented Oct 19, 2023

I'm not sure what the correct repo is to report this... I picked here because downgrading to notebook<7 fixes the issue.

Description

If I use this in a notebook cell:

import matplotlib.pyplot as plt
import numpy as np

%matplotlib notebook
plt.plot(np.arange(5))

I get the error:

Javascript Error: IPython is not defined
image

Reproduce

  1. conda create python=3.11 -n mynb
  2. pip install jupyter notebook matplotlib
  3. make new jupyter notebook with the above cell

Expected behavior

If I downgrade pip install "notebook<7" then a plot appears (with no error message)

Context

  • Operating System and version: windows 11
  • Browser and version: Chrome
  • Jupyter Notebook version:
$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.16.1
ipykernel        : 6.25.2
ipywidgets       : 8.1.1
jupyter_client   : 7.4.9
jupyter_core     : 5.4.0
jupyter_server   : 2.8.0
jupyterlab       : 4.0.7
nbclient         : 0.8.0
nbconvert        : 7.9.2
nbformat         : 5.9.2
notebook         : 7.0.6
qtconsole        : 5.4.4
traitlets        : 5.11.2
Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter notebook` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.
@qci-amos qci-amos added bug status:Needs Triage Applied to issues that need triage labels Oct 19, 2023
@qci-amos
Copy link
Author

This documentation:
https://matplotlib.org/stable/users/explain/figure/interactive.html#jupyter-notebooks-jupyterlab
says that the magic is supported:

%matplotlib notebook

@jtpio
Copy link
Member

jtpio commented Oct 19, 2023

Looks like it says the magic is supported in the classic notebook but not in JupyterLab though?

image

Notebook 7 is based on JupyterLab and reuses the notebook component from JupyterLab. Which is likely the reason why you get this error. The classic notebook used to provide JavaScript globals like IPython and JavaScript, but Notebook 7 does not anymore.

@qci-amos
Copy link
Author

This is a good point to clarify then because the way I opened my notebook was:

$ jupyter-notebook.exe mynb.ipynb

That is I assumed I was not using JupyterLab. When I click on About I see this:

image

@qci-amos
Copy link
Author

If you're saying this issue belongs in matplotlib then I can move it.

I would nevertheless ask if there's a more clear error message that could be raised.

@jtpio
Copy link
Member

jtpio commented Oct 19, 2023

In this case the fix would probably be to use %matplotlib widget?

@jtpio
Copy link
Member

jtpio commented Oct 19, 2023

That is I assumed I was not using JupyterLab. When I click on About I see this:

That's right, it's another application (Notebook 7). And the classic notebook refers to Notebook < 7.

@qci-amos
Copy link
Author

Yes, we can look into using different magic(s). The problem is that we have a lot of notebooks which use %matplotlib notebook from many non-software engineers so it might take us a while to update them. In the meantime, we added a notebook<7 pin in our stack while we sort this out.

And the classic notebook refers to Notebook < 7.

Ok, this point wasn't known to me. If this is the case, we can ask matplotlib to clarify their documentation? It sounds like you're saying this is likely a won't fix?

@jtpio
Copy link
Member

jtpio commented Oct 19, 2023

this point wasn't known to me. If this is the case, we can ask matplotlib to clarify their documentation? It sounds like you're saying this is likely a won't fix?

Update the matplotlib documentation to mention that Notebook 7 behaves like JupyterLab would indeed be useful 👍

There is an issue to discuss adding a compatibility layer with some classic notebook globals: #6394. Although for now there is no such thing available and not sure there will be. So for now this would indeed be a "won't fix" unless someone volunteers to implement #6394 (or similar).

@qci-amos
Copy link
Author

Just a quick note according to my colleagues: %matplotlib widget does not support live plotting whereas %matplotlib notebook does.

@JasonWeill
Copy link
Collaborator

Closing this because Notebook developers are not likely to make a change for this issue; see #6394 for the issue @jtpio mentioned. @qci-amos thank you for your contribution!

@rjk
Copy link

rjk commented Jan 25, 2024

In this case the fix would probably be to use %matplotlib widget?

👆 For any other novices like myself encountering the IPython is not defined problem when using notebook v7, this is the solution. Change the line that says %matplotlib notebook to instead say %matplotlib widget. This changes the backend used by matplotlib to one that works with notebook v7. Or if you don't need an interactive chart you can probably just comment the line out altogether.

@oihan-a
Copy link

oihan-a commented Oct 8, 2024

God bless you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status:Needs Triage Applied to issues that need triage
Projects
None yet
Development

No branches or pull requests

5 participants