Jupyter kernels manipulation and in other environments (docker, Lmod, etc.)

# Switch environments before running Jupyter kernels

Sometimes, one needs to execute Jupyter kernels in a different environment. Say you want to execute the kernel in a conda environment (that's easy, but actually misses setting certain environment variables). Or run it inside a Docker container. One could manually adjust the kernelspec files to set environment variables or run commands before starting the kernel, but envkernel automates this process.

envkernel is equally usable for end users (on their own systems or clusters) to easily access environments in Jupyter, or sysadmins deploying this access on systems they administer.

In general, there are two passes: First, install the kernel, e.g.: envkernel virtualenv --name=my-venv /path/to/venv. This parses some options and writes a kernelspec file with the the --name you specify. When Jupyter tries to start this kernel, it will execute the next phase. When Jupyter tries to run the kernel, the kernelspec file will re-execute envkernel in the run mode, which does whatever is needed to set up the environment (in this case, sets PATH to the /path/to/venv/bin/ that is needed). Then it starts the normal IPython kernel.

Available modes:

• conda: Activate a conda environment first.
• virtualenv: Activate a virtualenv first.
• docker: Run the kernel in a Docker container.
• singularity: Run the kernel in a singularity container.
• Lmod: Activate Lmod modules first.

## Installation

Available on the PiPI: pip install envkernel.

Or, you can install latest from Github in the usual way: pip install https://github.com/NordicHPC/envkernel/archive/master.zip

This is a single-file script and can be copied directly and added to PATH as well. By design, there are no dependencies except the basic Jupyter client (not notebook or any UI), and that is only needed at kernel-setup time, not at kernel-runtime. The script must be available both when a kernel is set up, and each time the kernel is started (and currently assumes they are in the same location).

## General usage and common arguments

General invocation:

envkernel [mode] [envkernel options] [mode-specific-options]


General arguments usable by all classes during the setup phase:

These options directly map to normal Jupyter kernel install options:

• mode: singularity, docker, lmod, or whatever mode is desired.

## Development and contributions

Developed at Aalto University Science-IT. Primary contact: Richard Darst. Contributions welcome from anyone. As of early 2019, it is mid 2019, it's usable but there may be bugs as it gets used in more sites.

## Project details

Uploaded source
Uploaded py3`