Micromamba & Jupiter-lab Kernels
micromamba is a package manager for the conda ecosystem. It is written in Rust and compiled to a small native binary
which can be installed anywhere in the filesystem.
Fully compatible with conda packages and environments and can be used as a drop-in replacement for conda or Mamba.
one of the main advantages of micromamba is that it is much faster than conda and mamba.
In my experience using micromamba is better then python venv, gave more control over the environment and packages.
nbdev - can used to build packages from jupyter notebooks, also can compile conda packages.
## Installation
For Linux and WSL, follow these steps to install Micromamba:
- Create a bin directory in your home directory
mkdir -p ~/bin
- Download and extract the micromamba binary
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xj bin/micromamba
Note: Some Linux systems do not call with bzip2 by default, you would need to install that in your system with
sudo apt install bzip2
Initialize the shell
Initialize the shell by running the following command:
./bin/micromamba shell init -s bash -p ~/micromamba -q
Enable the bioconda channels
set the channels to bioconda and conda-forge.
micromamba config prepend channels conda-forge
micromamba config append channels bioconda
Set the channel priority.
micromamba config set channel_priority strict
Tips and Tricks
To create a new environment, use the create
command:
micromamba create -n myenv
Activate the environment
Once you’ve created the environment, you can activate it using the activate
command followed by the name of the environment:
micromamba activate myenv
Install packages:
To install packages, use the install
command followed by the name of the package you want to install:
micromamba install -n myenv numpy
Install packages from a file:
To install packages from a file, used to install multiple packages at once, usally from a requirements.txt file or environment.yml file:
micromamba install -n myenv -f requirements.txt/ environment.yml
```tg
Export the environment:
To export the environment, use the export
command followed by the name of the environment, and redirect the output to a file:
micromamba env export -n myenv > environment.yml
Create an environment from a file:
In order to create an environment from a file, usally from a requirements.txt file or environment.yml file:
micromamba env create -f environment.yml
Remove the environment:
when you are done with the environment, you can remove it using the remove
command followed by the name of the environment:
micromamba remove -n myenv --all
Jupyter-lab
I use multiple kernels in jupyter-lab, it help me to keep my environments clean and organized.
For each project I create a new environment and a new kernel, this way I can use the same packages in different
projects with different versions.
There is less chance to break something in the environment and I can easily share the environment with my colleagues.
List the kernels
In order to list the kernels you need to run the following command:
jupyter kernelspec list
jupyter-lab intallation
In order to use micromamba with jupyter-lab you need to install the jupyter package and the ipykernel package.
micromamba install -n myenv jupyter
micromamba install -n myenv ipykernel
Then you need to create a kernel for the environment:
micromamba run -n myenv python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
Then you can start jupyter-lab, and select the kernel from the menu.
jupyter-lab
Rkernel
in order to use micromamba with R you need to install the R package and the IRkernel package.
This R package allows users to run an R kernel inside JupyterLab and Jupyter Notebook.
micromamba install -n myenv r-base r-essentials
to create a kernel for the environment, you need to run the following command:
micromamba run -n myenv R -e "IRkernel::installspec(user = FALSE)"
then you can start jupyter-lab, and select the kernel from the menu.
jupyter-lab