jupyterlite / xeus-python-kernel

xeus-python in JupyterLite
https://xeus-python-kernel.readthedocs.io
BSD 3-Clause "New" or "Revised" License
30 stars 19 forks source link

Add support for pip dependencies #102

Closed martinRenou closed 1 year ago

martinRenou commented 1 year ago

Would fix #100 and probably fix https://github.com/jupyterlite/xeus-python-kernel/issues/48

This is very much experimental for now.

Pip is running with the --no-deps option, meaning that the user would need to install the package dependencies from conda-forge/emscripten-forge/PyPI themselves.

Pip is not made for installing packages in another environment (it is supposed to install packages for the Python version it uses, nothing else), so we have to workaround this by doing some shenanigans to make it work. The --no-deps option is one of those workarounds.

I don't think we should support reading some requirements.txt file for now, at least not before pip packages are more correctly supported, if they ever are.

martinRenou commented 1 year ago

This does not work yet. The installed pip packages get filtered out by empack. We need to find a somewhat clean way for empack to not do this.

martinRenou commented 1 year ago

Building with https://github.com/emscripten-forge/empack/pull/65

Running pip install with --no-deps may be required, because it seems to not look properly into what's already installed in the prefix we install packages.

martinRenou commented 1 year ago

Local testing is working. Let's release empack.

Tried with pip-installed ipycanvas that ships a lab extension:

[LiteBuildApp] WARNING | 
            Installing pip dependencies. This is very much experimental so use this feature at your own risks.
            Note that you can only install pure-python packages.
            pip is being run with the --no-deps option to not pull undesired system-specific dependencies, so please
            install your package dependencies from emscripten-forge or conda-forge.

Using pip 23.2 from /home/martinrenou/micromamba/envs/xeus-python-kernel/lib/python3.11/site-packages/pip (python 3.11)
Collecting ipycanvas
  Using cached ipycanvas-0.13.1-py2.py3-none-any.whl (255 kB)
Installing collected packages: ipycanvas
Successfully installed ipycanvas-0.13.1
jupyterlite-xeus-python:xeus:copy:ext:ipycanvas
.  post_build:jupyterlite-xeus-python:xeus:copy:ext:ipycanvas
martinRenou commented 1 year ago

Working great on RTD

Screenshot from 2023-07-24 13-42-02

jtpio commented 1 year ago

Maybe we can also update the docs to remove this note?

image

And add a small yaml snippet to show how to install packages from PyPI when they are not available on conda forge?

martinRenou commented 1 year ago

Yes!

martinRenou commented 1 year ago

Thanks for the review!

martinRenou commented 1 year ago

Confirming in ipycanvas that installing a local Python package works nicely:

See https://github.com/jupyter-widgets-contrib/ipycanvas/pull/338

name: ipycanvas
channels:
  - https://repo.mamba.pm/emscripten-forge
  - https://repo.mamba.pm/conda-forge
dependencies:
  - pillow
  - numpy
  - ipywidgets
  - pip:
    - ..

Screenshot from 2023-07-25 09-52-17

martinRenou commented 1 year ago

@nthiery You can have a try with this!

The documentation for it is here https://xeus-python-kernel.readthedocs.io/en/latest/configuration.html#pip-packages

For example it is being used here https://github.com/jupyter-widgets-contrib/ipycanvas/pull/338