%pip install magic with inline comment causes InvalidRequirement error
Description
When using JupyterLite, adding an inline comment to a %pip install line e.g.:
%pip install seaborn # comment
the comment is interpreted as part of the package list, resulting in an InvalidRequirement error.
The behavior appears inconsistently across browsers — for example, it fails in Brave (Chromium-based) but not in Chrome.
Reproduce
-
Launch a JupyterLite notebook (e.g., from https://jupyterlite.github.io/demo).
-
In a code cell, enter the following line:
%pip install seaborn # required to use seaborn in jupyterlite -
Run the cell.
Expected behavior
The magic command parser strips the inline comments before passing the arguments to piplite, in this case resulting in seaborn being installed no matter the browser.
Context
- JupyterLite version: latest (from https://jupyterlite.github.io/demo as of 03-07-2025)
- Operating System and version: Ubuntu 24.04.2 LTS
- Browser and version: Firefox 139.0.4 (64-bit)
Browser Output
Paste the output from your browser Javascript console here.
Thanks @ArturoAmorQ for the report 👍
Looks like it's specific to the Pyodide kernel repo, so moving the issue over there: https://github.com/jupyterlite/pyodide-kernel