Open boisgera opened 1 year ago
matplotlib
is not installed by default in jupyterlite, you need to execute %pip install matplotlib
before execute your codes.
AFAICT, it is actually installed by default. At least I can import it and make some plots without any pip install:
My issue here is that in Jupyterlite,
%matplotlib notebook
import matplotlib
won't work
while
import matplotlib
%matplotlib notebook
does. Both work in the Jupyter lab setting (AFAICT).
@boisgera For jupyterlite, it use pyodide.runPython(code_string)
to run codes.
when code_string == "import matplotlib", pyodide can detect it (like import pkg_name
regex), and will help user to automatically and silently install matplotlib (You can open developer tool > Network tab, to see the network requests to confirm it).
when code_string == "%matplotlib notebook", import matplotlib
is invoked inside but cannot be detected by pyodide.
Ah, I was not aware of that, thanks @qqdaiyu55 , it's enlightening! And indeed, if I do for example
exec("import matplotlib.pyplot as plt")
in a notebook, I end up with the same failure and error message. Same thing if I define a matplotlib_loader.py
file whose content is:
import matplotlib
and make a
from matplotlib_loader import *
in the notebook.
Would it be possible to use import hooks (https://docs.python.org/3/reference/import.html#import-hooks) to have the same auto-loading property on import, but with a more robust behavior ? (Any import could be detected this way AFAICT, including the one triggered by %matplotlib notebook
.)
Regards,
Sébastien
Description
generates the error
Reproduce
%import matplotlib
in the first cell. Do NOT import matplotib beforehandExpected behavior
This code should execute without any visible output (and enable the notebook mode for matplotlib). At the moment, this works if you import matplotlib beforehand but in the Jupyter lab context both options work.
Context
Jupyter lite version : Version 0.1.0-beta.17