Hello! I’m trying to run the following code in a Jupyter notebook, but I’m encountering an error:
%matplotlib widget
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
The error I receive is: ModuleNotFoundError: No module named 'ipympl'
I’m using a cloud-based Jupyter environment and I’m unable to use pip install ipympl
directly. What might be the solution for this?
Apologies, I’m new to this.
Marina
There’s no way around it. You need ipympl
for this. (I assume.You actually don’t provide a minimal reproducible example related to what you are actually trying to do.) As you can read here this is how current Jupyter offerings work with interactive plots:
" Leveraging the Jupyter interactive widgets framework, ipympl
enables the interactive features of matplotlib in the Jupyter notebook and in JupyterLab.
Besides, the figure canvas
element is a proper Jupyter interactive widget which can be positioned in interactive widget layouts."
You say you unable to use pip install ipympl
directly? Are you sure that is the case? Did you try making a new cell at the very top of your .ipynb
file where you want to run these plots and put in it %pip install ipympl
and run that? (Including that magic %
symbol here is very important.) What happens if you do? Ideally, that works and runs to completion without error and then you can restart the kernel. Following that you have to do a hard refresh on the page in your browser. On a Mac in Chrome browser, this is Shift + Command + R
. This is critical when you install this way because a lot of changes happen in the internals of the browser and browsers like to hold on to the old settings and code in memory to try to give the user a more stable experience. You want to change things so you need to do extra steps. If following that you still don’t see plot interactivity, shut down everything , connection to cloud offering, browser, computer, all of it, and then try bringing it back up and before you try running the plot code again, do the hard refresh again.
Please read this answer here for more details.
I would strongly urge you to adopt the more explicit use of %matplotlib ipympl
and not the legacy %matplotlib widget
. Though the basic example here in the ipympl documentation says that legacy invocation will work it is better to signal to yourself and others what is involved here.
Thanks for the advice, a full shutdown and hard reset helped! %matplotlib ipympl
is working now. %matplotlib widget
isn’t, but that’s fine. Thanks again!
That’s odd to me given what the documentation says, but explicit & current is always better anyway.