jupyterlite / xeus

JupyterLite loader for Xeus kernels
https://jupyterlite-xeus.readthedocs.io
BSD 3-Clause "New" or "Revised" License
22 stars 11 forks source link

Installing Additional Packages at runtime #67

Open psychemedia opened 1 year ago

psychemedia commented 1 year ago

Is there any way for a user to installing additional packages from pip into a running xeus-python kernel?

martinRenou commented 1 year ago

It's not available (yet?). I guess it could be done for pure Python packages, but for now you'll need to rely on conda-forge and emscripten-forge packages.

DerThorsten commented 1 year ago

It's not yet working but we working on integrating micropip and a very slim mamba (picomamba) into xeus-python.

martinRenou commented 1 year ago

I guess the original question was concerning pre-installed packages?

DerThorsten commented 1 year ago

Is there any way for a user to installing additional packages from pip into a running xeus-python kernel?

but his question is about installing in a "running" kernel, ie not pre-install?

psychemedia commented 1 year ago

Original comment was more along the lines of: I am in a notebook running a xeus-python kernel; how do I do an equivalent of %pip install newPackage.

psychemedia commented 1 year ago

Elsewhere, I learned that the default pyodide kernel now supports %pip magic.

jtpio commented 1 year ago

Elsewhere, I learned that the default pyodide kernel now supports %pip magic.

Yes this was added in 0.1.0b14: https://jupyterlite.readthedocs.io/en/latest/changelog.html#b14

jtpio commented 1 year ago

For reference micropip should now be available on conda-forge: https://github.com/conda-forge/micropip-feedstock

It would be interesting to get it to install packages on the fly in the xeus python kernel.

jtpio commented 1 year ago

It would be interesting to get it to install packages on the fly in the xeus python kernel.

Gave this a try with the following environment.yml:

name: test
channels:
- https://repo.mamba.pm/emscripten-forge
- https://repo.mamba.pm/conda-forge
dependencies:
- micropip

Importing micropip works:

import micropip
micropip.__version__
# '0.3.0'

Installing a package with:

micropip.install('emoji')

Then importing it with:

import emoji

Gives the following:

image

psychemedia commented 11 months ago

Any updates on the ability to install packages at runtime?

(To a certain extent, NOT supporting this might be useful in an educational context, if you want students to be limited to using just and only what is provided...)

Having micropip available might be handy when working out what's required when putting toigether a new environment, though...

jtpio commented 11 months ago

(To a certain extent, NOT supporting this might be useful in an educational context, if you want students to be limited to using just and only what is provided...)

Probably this would be the case depending on whether the micropip (or equivalent) package is available in the kernel environment, which would be controlled by the site deployer.

martinRenou commented 11 months ago

The coming update to the new emscripten-wasm32 platform may allow using micropip? @DerThorsten

psychemedia commented 11 months ago

Thinking about the environment.yaml config file, the "normal" config file spec allows you to install pip as a dependency and then provide a sublist of pip packages to install from PyPI. Is there any sense in which you can installpip or micropip packages as part of the xeus-python-kernel's environment.yaml file?

martinRenou commented 11 months ago

As of recently xeus-python allows partial support for installing pip dependencies: https://xeus-python-kernel.readthedocs.io/en/latest/configuration.html#pip-packages

Though you should not specify pip in the dependency list. We should probably take care of this case though. I'll open an issue for that.