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

Matplotlib magic command not available #139

Closed
ElioDiNino opened this issue Feb 22, 2024 · 19 comments · Fixed by ipython/ipython#14356
Closed

Matplotlib magic command not available #139

ElioDiNino opened this issue Feb 22, 2024 · 19 comments · Fixed by ipython/ipython#14356
Labels
bug Something isn't working

Comments

@ElioDiNino
Copy link

Description

The matplotlib magic command (%matplotlib) is unavailable despite the example using it here. It's not clear to me whether this is a JupyterLite bug, or just a bug with the demo so I am putting it here for now.

image

Reproduce

  1. Go to the linked example
  2. Run all of the cells
  3. See error as shown in my screenshot

Expected behavior

The magic command should execute without issue. A good way to test this would be being able to run %matplotlib --list.

Context

  • JupyterLite version: 0.2.3
  • Operating System and version: MacOS Sonoma 14.3.1
  • Browser and version: Chrome 121.0.6167.184 (Official Build) (arm64)
Browser Output
/favicon.ico:1 
   Failed to load resource: the server responded with a status of 404 ()

remoteEntry.0dca0b46350f0c25c608.js:1 No satisfying version (^4.0.12) of shared module @jupyterlab/docregistry found in shared scope default.
Available versions: 4.0.11 from _JUPYTERLAB.CORE_OUTPUT
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/rendermime (required ^4.0.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 6.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/coreutils (required ^6.0.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/application (required ^4.0.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/ui-components (required ^4.0.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 4.1.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/apputils (required ^4.1.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/translation (required ^4.0.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
manifest.webmanifest:1 Manifest: property 'url' ignored, should be within scope of the manifest.
manifest.webmanifest:1 Manifest: property 'url' of 'shortcut' not present.
manifest.webmanifest:1 Manifest: property 'url' ignored, should be within scope of the manifest.
manifest.webmanifest:1 Manifest: property 'url' of 'shortcut' not present.
remoteEntry.0dca0b46350f0c25c608.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/notebook (required ^4.0.12)
c @ remoteEntry.0dca0b46350f0c25c608.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/notebook (required ^4.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/logconsole (required ^4.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 No satisfying version (^4.1.0) of shared module @jupyterlab/outputarea found in shared scope default.
Available versions: 4.0.11 from _JUPYTERLAB.CORE_OUTPUT
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/translation (required ^4.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/rendermime (required ^4.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 7.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/services (required ^7.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/settingregistry (required ^4.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9f387e5e108e458f62c3.js:1 Unsatisfied version 4.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/mainmenu (required ^4.1.0)
p @ remoteEntry.9f387e5e108e458f62c3.js:1
remoteEntry.9117113815033289c4d5.js:1 Unsatisfied version 0.2.3 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlite/kernel (required ~0.1.0-beta.18)
s @ remoteEntry.9117113815033289c4d5.js:1
remoteEntry.9117113815033289c4d5.js:1 Unsatisfied version 6.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/coreutils (required ^5.5.2)
s @ remoteEntry.9117113815033289c4d5.js:1
remoteEntry.9117113815033289c4d5.js:1 Unsatisfied version 2.1.2 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @lumino/coreutils (required ^1.11.0)
s @ remoteEntry.9117113815033289c4d5.js:1
consumes:73 Unsatisfied version 6.0.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/coreutils (required ^6.0.12)
p @ consumes:73
remoteEntry.f69e84c5aaec83c179ca.js:1 Unsatisfied version 2.1.2 of shared singleton module @lumino/signaling (required ^1.4.3)
f @ remoteEntry.f69e84c5aaec83c179ca.js:1
remoteEntry.f69e84c5aaec83c179ca.js:1 Unsatisfied version 2.1.2 of shared singleton module @lumino/coreutils (required ^1.5.3)
f @ remoteEntry.f69e84c5aaec83c179ca.js:1
remoteEntry.960d5d0f875a651e597f.js:1 Unsatisfied version 2.1.2 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @lumino/coreutils (required ^1.11.0)
f @ remoteEntry.960d5d0f875a651e597f.js:1
remoteEntry.960d5d0f875a651e597f.js:1 Unsatisfied version 2.1.2 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @lumino/signaling (required ^1.10.0)
f @ remoteEntry.960d5d0f875a651e597f.js:1
remoteEntry.2916befd91bdb8847e88.js:1 Unsatisfied version 2.0.1 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @lumino/messaging (required ^1.4.3)
d @ remoteEntry.2916befd91bdb8847e88.js:1
remoteEntry.2916befd91bdb8847e88.js:1 Unsatisfied version 2.3.1 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @lumino/widgets (required ^1.19.0)
d @ remoteEntry.2916befd91bdb8847e88.js:1
remoteEntry.5e71a5e8dcb6330c0085.js:1 Unsatisfied version 1.9.4 from jupyter-leaflet of shared singleton module leaflet (required =1.4.0)
s @ remoteEntry.5e71a5e8dcb6330c0085.js:1
remoteEntry.6a37df5d4590b29196a3.js:1 Unsatisfied version 4.1.11 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @jupyterlab/apputils (required ^3.5.1)
s @ remoteEntry.6a37df5d4590b29196a3.js:1
remoteEntry.c764a537ae4fed4fb4ca.js:1 Unsatisfied version 2.3.1 from _JUPYTERLAB.CORE_OUTPUT of shared singleton module @lumino/widgets (required ^1.37.2)
s @ remoteEntry.c764a537ae4fed4fb4ca.js:1
service-manager.js:48 Existing JupyterLite ServiceWorkers unregistered
service-manager.js:50 Registering new JupyterLite ServiceWorker https://jupyterlite.github.io/demo/service-worker.js
service-manager.js:53 JupyterLite ServiceWorker was sucessfully registered
index.js:171 Kernel filesystem and JupyterLite contents will be synced
toc.js:513 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'type')
at Ce (toc.js:513:17)
at toc.js:421:41
at Array.forEach ()
at s (toc.js:419:41)
at c (toc.js:480:17)
at d (index.es6.js:555:18)
at e.emit (index.es6.js:513:17)
at s.emit (index.es6.js:112:17)
at ce._onCellInViewportChanged (widget.js:652:37)
at d (index.es6.js:555:18)
Ce @ toc.js:513
(anonymous) @ toc.js:421
s @ toc.js:419
c @ toc.js:480
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
_onCellInViewportChanged @ widget.js:652
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
set inViewport @ widget.js:164
attachWidget @ windowing.js:198
insertWidget @ index.es6.js:2516
_updateForDeferMode @ widget.js:758
_runOnIdleTime @ widget.js:727
await in _runOnIdleTime (async)
s @ toc.js:419
c @ toc.js:480
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
_onCellInViewportChanged @ widget.js:652
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
set inViewport @ widget.js:164
attachWidget @ windowing.js:198
insertWidget @ index.es6.js:2516
_updateForDeferMode @ widget.js:758
_runOnIdleTime @ widget.js:727
await in _runOnIdleTime (async)
onUpdateRequest @ widget.js:425
onUpdateRequest @ widget.js:1520
processMessage @ index.es6.js:1206
u @ index.es6.js:412
i @ index.es6.js:166
m @ index.es6.js:463
(anonymous) @ index.es6.js:140
Promise.then (async)
n @ index.es6.js:140
p @ index.es6.js:431
e.postMessage @ index.es6.js:196
update @ index.es6.js:1068
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
_triggerChange @ truststatus.js:191
_onModelChanged @ truststatus.js:143
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
onModelContentChanged @ widget.js:383
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
triggerContentChange @ model.js:352
_onCellsChanged @ model.js:303
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
(anonymous) @ celllist.js:136
_onSharedModelChanged @ celllist.js:136
d @ index.es6.js:555
e.emit @ index.es6.js:513
emit @ index.es6.js:112
C._onYCellsChanged @ ynotebook.js:171
o @ function.js:19
pe @ yjs.mjs:1955
Xn @ yjs.mjs:4916
_callObserver @ yjs.mjs:5684
(anonymous) @ yjs.mjs:3212
o @ function.js:19
un @ yjs.mjs:3242
gn @ yjs.mjs:3368
transact @ yjs.mjs:525
transact @ ydocument.js:164
fromJSON @ ynotebook.js:453
fromJSON @ model.js:279
(anonymous) @ context.js:553
Promise.then (async)
_revert @ context.js:547
initialize @ context.js:203
(anonymous) @ manager.js:550
Promise.then (async)
_createOrOpenDocument @ manager.js:550
open @ manager.js:374
openOrReveal @ manager.js:401
handleOpen @ listing.js:976
evtDblClick @ listing.js:1185
handleEvent @ listing.js:594
Show 86 more frames
Show less
index.js:51 Pyodide contents will be synced with Jupyter Contents
pyodide.asm.js:9 Loading micropip, packaging
pyodide.asm.js:9 Loaded micropip, packaging
pyodide.asm.js:9 Loading ssl, openssl
pyodide.asm.js:9 Loaded openssl, ssl
pyodide.asm.js:9 Loading sqlite3
pyodide.asm.js:9 Loaded sqlite3
pyodide.asm.js:9 Loading Pygments, decorator, jedi, parso, six
pyodide.asm.js:9 Loaded Pygments, decorator, jedi, parso, six
336.0a90bd910629a565bb7e.js?v=0a90bd910629a565bb7e:1 Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel, fallback to fetching individual model state. Reason: Control comm did not respond in time
overrideMethod @ console.js:213
_loadFromKernel @ 336.0a90bd910629a565bb7e.js?v=0a90bd910629a565bb7e:1
await in _loadFromKernel (async)
_loadFromKernel @ 134.fe2572ece3b7955c89bb.js?v=fe2572ece3b7955c89bb:1
restoreWidgets @ 134.fe2572ece3b7955c89bb.js?v=fe2572ece3b7955c89bb:1
Show 1 more frame
Show less
pyodide.asm.js:9 six already loaded from default channel
pyodide.asm.js:9 packaging already loaded from default channel
pyodide.asm.js:9 Loading matplotlib, cycler, fonttools, kiwisolver, numpy, Pillow, pyparsing, python-dateutil, pytz, matplotlib-pyodide
pyodide.asm.js:9 Loaded Pillow, cycler, fonttools, kiwisolver, matplotlib, matplotlib-pyodide, numpy, pyparsing, python-dateutil, pytz

@ElioDiNino ElioDiNino added the bug Something isn't working label Feb 22, 2024
@jtpio
Copy link
Member

jtpio commented Feb 23, 2024

Thanks @ElioDiNino for the report.

I was able to reproduce the issue with the latest demo: https://jupyterlite.github.io/demo/lab/index.html

Not sure when it started to fail. Maybe @martinRenou will know more.

@martinRenou
Copy link
Member

It's unclear to me what changed here. It indeed used to work. The traceback only seems to show files from IPython which did not change since a year.

Invoking @ianthomas23 who was looking into the matplotlib magic implementation, also @Carreau may know a bit more what changed recently in IPython.

Anyway, we could probably fix it by providing a simple implementation of arg_split here https://github.com/ipython/ipython/blob/main/IPython/utils/_process_emscripten.py#L21. Maybe

def arg_split(s, posix=False, strict=True):
    raise s.split(" ")

@Carreau
Copy link

Carreau commented Feb 26, 2024

Ah, this was creating crashes for emscripten/sagemath, so yes this is a recent change to accomodate emscripten. I'll make a fix.

@Carreau
Copy link

Carreau commented Feb 26, 2024

If you can pin IPython to !=8.22.0,!=8.22.1 and it can wait a month for release that's great. Otherwise I can try to make a 8.22.2 by end of week.

@martinRenou
Copy link
Member

Thanks for the prompt PR. Pinning IPython is a fine workaround for now!

@ericpre
Copy link

ericpre commented Feb 26, 2024

How do you pin ipython in jupyterlite? It is already included and downgrading doesn't seem to work:

import micropip
await micropip.install("ipython==8.21.0")

Give the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 2
      1 import micropip
----> 2 await micropip.install("ipython==8.21.0")

File /lib/python3.11/site-packages/micropip/_commands/install.py:142, in install(requirements, keep_going, deps, credentials, pre, index_urls, verbose)
    130     index_urls = package_index.INDEX_URLS[:]
    132 transaction = Transaction(
    133     ctx=ctx,
    134     ctx_extras=[],
   (...)
    140     index_urls=index_urls,
    141 )
--> 142 await transaction.gather_requirements(requirements)
    144 if transaction.failed:
    145     failed_requirements = ", ".join([f"'{req}'" for req in transaction.failed])

File /lib/python3.11/site-packages/micropip/transaction.py:204, in Transaction.gather_requirements(self, requirements)
    201 for requirement in requirements:
    202     requirement_promises.append(self.add_requirement(requirement))
--> 204 await asyncio.gather(*requirement_promises)

File /lib/python3.11/site-packages/micropip/transaction.py:211, in Transaction.add_requirement(self, req)
    208     return await self.add_requirement_inner(req)
    210 if not urlparse(req).path.endswith(".whl"):
--> 211     return await self.add_requirement_inner(Requirement(req))
    213 # custom download location
    214 wheel = WheelInfo.from_url(req)

File /lib/python3.11/site-packages/micropip/transaction.py:290, in Transaction.add_requirement_inner(self, req)
    287 # Is some version of this package is already installed?
    288 req.name = canonicalize_name(req.name)
--> 290 satisfied, ver = self.check_version_satisfied(req)
    291 if satisfied:
    292     logger.info(f"Requirement already satisfied: {req} ({ver})")

File /lib/python3.11/site-packages/micropip/transaction.py:235, in Transaction.check_version_satisfied(self, req)
    231 if req.specifier.contains(ver, prereleases=True):
    232     # installed version matches, nothing to do
    233     return True, ver
--> 235 raise ValueError(
    236     f"Requested '{req}', " f"but {req.name}=={ver} is already installed"
    237 )

ValueError: Requested 'ipython==8.21.0', but ipython==8.22.1 is already installed

Carreau added a commit to Carreau/ipython that referenced this issue Feb 26, 2024
@martinRenou
Copy link
Member

Concerning the pyolite kernel I don't know if it's even possible to do this, but using jupyterlite-xeus and xeus-python you should be able to specify the IPython version in the environment.yml file

@ericpre
Copy link

ericpre commented Feb 26, 2024

Thank you @martinRenou for following up. This is what I understood too from reading the documentation and I tried that but hit another issue - h5py is not yet available on emscripten-forge, emscripten-forge/recipes#685. 🤷

@epugh
Copy link

epugh commented Feb 26, 2024

I'd love to see a simple example of the use of jupyterlite-xeus... I've read about it, but been a bit daunted to try something new ;-)

@martinRenou
Copy link
Member

h5py is not yet available on emscripten-forge, emscripten-forge/recipes#685. 🤷

Yeah, it would be great to continue this PR.

I'd love to see a simple example of the use of jupyterlite-xeus

One simple example is https://github.com/jupyterlite/xeus-python-demo, just use the template repository and change the environment.yml adding the packages you want in there :) Feel free to open an issue requesting help if needed

Carreau added a commit to ipython/ipython that referenced this issue Feb 27, 2024
@ElioDiNino
Copy link
Author

Thanks for all the work on this! With regards to the IPython release, @Carreau when can I expect the next version?

I'm not sure how I can properly pin the IPython version for my JupyterLite build (doing so in the requirements.txt did not fix the issue for me)

@Carreau
Copy link

Carreau commented Feb 28, 2024

Usually I do a monthly release on the last Friday of each month.

@ElioDiNino
Copy link
Author

Usually I do a monthly release on the last Friday of each month.

Ah, so the next release will be at the end of March?

@pierre-haessig
Copy link

If you can pin IPython to !=8.22.0,!=8.22.1 and it can wait a month for release that's great. Otherwise I can try to make a 8.22.2 by end of week.

Hi @Carreau, as mentioned in the discussion, any Jupyterlite+Pyodide based notebook using an IPython magic (%run, %matplotlib...) is currently broken without possibility to implement a quick fix (unlike xeus-python backed ones). So, if possible, I would welcome an anticipated release of IPython 8.22.2.

@Carreau
Copy link

Carreau commented Mar 4, 2024

I just released 8.22.2 a few minutes ago, that should fix things. It will take a few hours to be on conda-forge

@ElioDiNino
Copy link
Author

I just released 8.22.2 a few minutes ago, that should fix things. It will take a few hours to be on conda-forge

Much appreciated! I will now close this issue since creating a new build pulls in the latest IPython version and everything runs as expected. @jtpio feel free to reopen it if you only want it closed after it is resolved in the JupyterLite demo.

@jtpio
Copy link
Member

jtpio commented Mar 4, 2024

Thanks all!

Much appreciated! I will now close this issue since creating a new build pulls in the latest IPython version and everything runs as expected. @jtpio feel free to reopen it if you only want it closed after it is resolved in the JupyterLite demo.

Normally this should be picked up automatically by the demo repo which uses the Pyodide kernel and installs ipython at kernel startup: https://github.com/jupyterlite/pyodide-kernel/blob/1b6c80494fed67c7ca9dfb8c529f0a92130f4975/packages/pyodide-kernel/src/worker.ts#L85

@pierre-haessig
Copy link

Indeed no need to rebuild. My deployment got fixed as well. Thanks a lot @Carreau!

@martinRenou
Copy link
Member

Note that xeus-python should also be pulling the latest IPython automatically now as it has been updated on emscripten-forge.

Thanks a lot @Carreau !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants