The default Python kernel for JupyterLite powered by pyodide, supports installing packages from a number of sources:
pyodide
py3-none-any.whl
cp310-cp310-emscripten_3_1_14_wasm32.whl
%pip install -q
¶The recommended way to install packages is the %pip
magic:
%pip install -q "traitlets >=5" ipython
{hint}
- `%pip` helps keep your notebooks **portable** between different IPython runtimes.
- `-q` helps keep this "setup" step reasonable when run under `ipykernel`
%pip
supports a number of additional options:
%pip --help
--requirements
¶In addition to (or instead of) package names, any number of --requirements
(or
shorthand -r
) may be given, pointing to requirements files.
These can be relative or absolute (though this can be tricky to predict).
%pip install -r data/requirements.txt -r ../data/more-requirements.txt
{hint}
Using a `requirements.txt` is a good way to separate your content from your environment,
and could be combined with other techniques to make even more portable notebooks.
Some known unsupported features:
.
or other local in-development paths%pip install
a build tool (e.g. flit
).whl
--editable
(or -e.
) local or remote paths.whl
URLs or local archives--constraint
(or -c
) constraint filesEven if a PyPI package would be installable in the Pyodide kernel, sometimes its dependencies won't be.
try:
%pip install jupyter_server
except Exception as err:
print(err)
--verbose
¶As the real pip
doesn't have an equivalent, %pip
in the Pyodide kernel maps the
--verbose
flag to keep_going
.
try:
%pip install --verbose jupyter_server
except Exception as err:
print(err)
{warning}
Leaving this on for real `pip` generates a **lot** of output!
--no-deps
¶If some missing dependencies don't bother you, you can forge ahead without any
dependencies with the --no-deps
flag.
%pip install jupyter_server --no-deps
import jupyter_server
jupyter_server.__version__
While importable, it won't have all of its features, and may require special approaches to access features.
try:
import jupyter_server.services.contents.filemanager
except Exception as err:
print(err)
Going down this road can be long, depending on how much you really need a particular function.
The piplite
package is importable, and can be used directly.
piplite
¶piplite
needs to be imported before it is used.
import piplite
This package won't be installable in a "traditional" IPython installation, so you can gate it with an import check:
try:
import piplite
except ImportError:
piplite = None
piplite.install
¶
piplite.install
is a wrapper aroundmicropip.install
, and offers more browser-focused options than%pip
{warning}
Due to browser limitations, `piplite.install` is an _asynchronous` function, so it must be `await`ed.
piplite.install
supports either a single package:
await piplite.install("traitlets")
or a list of packages:
await piplite.install(["traitlets", "IPython"])
It also has many additional options:
?piplite.install