pyodide / micropip

A lightweight Python package installer for Pyodide
https://micropip.pyodide.org
Mozilla Public License 2.0
68 stars 16 forks source link

ENH: A micropip.main() for %pip in Jupyter #82

Open westurner opened 9 months ago

westurner commented 9 months ago

STORY: Users can use %pip to install with micropip in JupyterLite notebooks (so that notebooks with %pip will work with all Python Jupyter kernels)


%pip  # works in jupyter_console, jupyter notebook, jupyterlab, but not in JupyterLite
!pip  # doesn't work in pyodide (because there's no $SHELL; jupyterlite/jupyterlite#949)

# Works with the pyodide Jupyter kernel but not ipykernel or xeus-python:
import micropip
await micropip.install(["pandas",])

A main for %pip would need or could have at least:

def test_micropip_main_help_version(capsys):
    assert micropip.main(["-h"]) == 0    
    assert micropip.main(["--help"]) == 0
    captured = capsys.readouterr()
    assert "micropip" in captured.out

    assert micropip.main(["--version"]) == 0
    captured = capsys.readouterr()
    assert "micropip" in captured.out

def test_micropip_main_install(capsys):
    assert micropip.main(["install", "testpkg"]) == 0

##

def test_micropip_main_list(capsys):
    assert micropip.main(["list"]) == 0

def test_micropip_main_freeze(capsys):
    assert micropip.main(["freeze"]) == 0
rth commented 9 months ago

STORY: Users can use %pip to install with micropip in JupyterLite notebooks

That's already the case https://jupyterlite.readthedocs.io/en/latest/howto/pyodide/packages.html#installing-packages-at-runtime,

%pip --help

usage: piplite [-h] [--verbose] [--quiet] [--requirements [REQUIREMENTS ...]]
               [--no-deps] [--pre]
               {help,install} [packages ...]

a pip-like wrapper for `piplite` and `micropip`

positional arguments:
  {help,install}        action to perform
  packages              package names (or wheel URLs) to install

options:
  -h, --help            show this help message and exit
  --verbose, -v         whether to print more output
  --quiet, -q           only show the minimum output
  --requirements [REQUIREMENTS ...], -r [REQUIREMENTS ...]
                        paths to requirements files
  --no-deps             whether dependencies should be installed
  --pre                 whether pre-release packages should be considered

although it doesn't support the other subcommand than install that micropip has, so maybe those could be added.