Skip to content

Instantly share code, notes, and snippets.

@wolfv
Last active Dec 22, 2021
Embed
What would you like to do?
micromamba usage

Installation

micromamba works in the bash & zsh shell on Linux & OS X. It's completely statically linked, which allows you to drop it in a compatible Linux or OS X and just execute it.

Download and unzip the executable (from the official conda-forge package):

wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba --strip-components=1

We can use ./micromamba shell init ... to initialize a shell (.bashrc) and a new root environment:

./micromamba shell init -s bash -p ~/micromamba
source ~/.bashrc

Now you can activate the base environment and install new packages, or create other environments.

micromamba activate
micromamba install python=3.6 jupyter -c conda-forge
micromamba create -p /some/new/prefix xtensor -c conda-forge

OS X

Micromamba has OS X support as well. Instructions are largely the same:

curl -Ls https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba
mv bin/micromamba ./micromamba
./micromamba shell init -s zsh -p ~/micromamba
source ~/.zshrc
micromamba activate
micromamba install python=3.6 jupyter -c conda-forge

ARM 64 and PPC support

There are packages for micromamba available for ARM 64 and PPC. Just use the Linux instructions and exchange the package with the one found on anaconda.org.

Windows

Micromamba also has Windows support! For Windows, we recommend powershell. Below are the commands to get micromamba installed.

Invoke-Webrequest -URI https://micromamba.snakepit.net/api/micromamba/win-64/latest -OutFile micromamba.tar.bz2
C:\PROGRA~1\7-Zip\7z.exe x micromamba.tar.bz2 -aoa
C:\PROGRA~1\7-Zip\7z.exe x micromamba.tar -ttar -aoa -r Library\bin\micromamba.exe
$Env:MAMBA_ROOT_PREFIX=(Join-Path -Path $HOME -ChildPath micromamba)
$Env:MAMBA_EXE=(Join-Path -Path (Get-Location) -ChildPath micromamba.exe)
.\micromamba.exe create -f ./test/env_win.yaml -y

API

We should soon figure out an automated process to use the latest version of micromamba. We can use the anaconda api: https://api.anaconda.org/release/conda-forge/micromamba/latest to find all the latest packages, we just need to select the one for the right platform.

name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test_shells:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: install micromamba
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba --strip-components=1
else
wget -qO- https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba
mv bin/micromamba ./micromamba
fi
./micromamba shell init -s bash -p ~/micromamba
mkdir -p ~/micromamba/pkgs/
- name: install deps
shell: bash -l {0}
run: |
export MAMBA_ROOT_PREFIX=~/micromamba
export MAMBA_EXE=$(pwd)/micromamba
. $MAMBA_ROOT_PREFIX/etc/profile.d/mamba.sh
./micromamba create -f ./test/env_unix.yaml -y
- name: run tests
shell: bash -l {0}
run: |
export MAMBA_ROOT_PREFIX=~/micromamba
export MAMBA_EXE=$(pwd)/micromamba
. $MAMBA_ROOT_PREFIX/etc/profile.d/mamba.sh
micromamba activate test
pip install -e .
pytest test/
test_win_shells:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
steps:
- uses: actions/checkout@v2
- name: install micromamba
shell: powershell
run: |
Invoke-Webrequest -URI https://micromamba.snakepit.net/api/micromamba/win-64/latest -OutFile micromamba.tar.bz2
C:\PROGRA~1\7-Zip\7z.exe x micromamba.tar.bz2 -aoa
C:\PROGRA~1\7-Zip\7z.exe x micromamba.tar -ttar -aoa -r Library\bin\micromamba.exe
MOVE -Force Library\bin\micromamba.exe micromamba.exe
.\micromamba.exe shell init -s powershell -p ~/micromamba
- name: install deps
shell: powershell
run: |
$Env:MAMBA_ROOT_PREFIX=(Join-Path -Path $HOME -ChildPath micromamba)
$Env:MAMBA_EXE=(Join-Path -Path (Get-Location) -ChildPath micromamba.exe)
.\micromamba.exe create -f ./test/env_win.yaml -y
- name: run tests
shell: powershell
run: |
# micromamba activate test
~/micromamba/envs/test/Scripts/pip.exe install -e .
~/micromamba/envs/test/Scripts/pytest.exe test/
if ($LastExitCode -ne 0) {
exit 1
}
@OlafHaag
Copy link

OlafHaag commented Aug 19, 2020

Hi! I want to try micromamba in a gitlab CI pipeline, but when ./micromamba shell init -s bash -p ~/micromamba gets called I get an error:

$ ./micromamba shell init -s bash -p ~/micromamba
/bin/sh: eval: line 104: ./micromamba: not found
ERROR: Job failed: exit code 127

What is this line supposed to do? I want to create an environment from my own environment.yml. I'm still pretty clueless about what I'm supposed to do in my CI Setup. Could you help me out, please?

@porteusconf
Copy link

porteusconf commented Sep 16, 2020

Googling for gitlab ci/cd "micromamba" has postings by folks trying that, like https://discourse.pymc.io/t/using-pymc3-docker-container-in-ci-pipeline/5656/4
Here's a .gitlab-ci.yml one poster is using, but read all his posts at above link for details: https://gitlab.com/OlafHaag/NeuroPsyResearchAnalysis/-/blob/71ba6f9105aeb94d7867a6b5622b136ca6d7f7d5/.gitlab-ci.yml
You've got to remember the microsamba is quite new and a wip (work in progress) so expect changes as it develops. I'll be trying a gitlab ci/cd with micromamba and will post back here if I get it working.

@OlafHaag
Copy link

OlafHaag commented Sep 16, 2020

Googling for gitlab ci/cd "micromamba" has postings by folks trying that, like https://discourse.pymc.io/t/using-pymc3-docker-container-in-ci-pipeline/5656/4
Here's a .gitlab-ci.yml one poster is using, but read all his posts at above link for details: https://gitlab.com/OlafHaag/NeuroPsyResearchAnalysis/-/blob/71ba6f9105aeb94d7867a6b5622b136ca6d7f7d5/.gitlab-ci.yml
You've got to remember the microsamba is quite new and a wip (work in progress) so expect changes as it develops. I'll be trying a gitlab ci/cd with micromamba and will post back here if I get it working.

Yes, both links you provided lead to posts made by me. In that CI-setup I used miniconda to install micromamba. But I wanted to use the above installation instructions to circumvent having to install miniconda first and instead install micromamba directly.

@cbrnr
Copy link

cbrnr commented Sep 17, 2020

Since wget is not installed on macOS by default, the first line of the instructions should use curl:

curl -Ls https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba

@wolfv
Copy link
Author

wolfv commented Sep 17, 2020

@OlafHaag sorry for being super late with a reply. Did you use a non-glibc docker image (e.g. Alpine Linux)? conda packages (including micromamba) require glibc on Linux, so Alpine doesn't work.

You can use many other distros: Ubuntu, Debian, Fedora ...
I think the latest ubuntu docker images are also reasonably small (30 Mb or something).

@wolfv
Copy link
Author

wolfv commented Sep 17, 2020

@cbrnr thanks for the suggestion! Will update.

@nthiery
Copy link

nthiery commented Sep 22, 2020

Sounds all very promising. I am looking forward a docker base image similar to conda/miniconda3 !

@OlafHaag
Copy link

OlafHaag commented Sep 22, 2020

@wolfv I'll have to try your suggestion another time. I'm not touching a running system right now. ^^

@NegatioN
Copy link

NegatioN commented Oct 15, 2020

This works almost perfectly for me. A few hiccups with how errors are displayed when I can't satisfy all version depdendencies, but otherwise fine.

The only thing I think I might miss is something akin to nb_conda_kernels for this, which can allow jupyter to discover several kernels. However it seems like the implementation of that depends directly on having a bundled python in the base environment 🤷

Solving this might be out of scope, but is there any chance it's on your roadmap?

@wolfv
Copy link
Author

wolfv commented Oct 15, 2020

it's not on my roadmap but you can create a base environment (just do micromamba install python=3.7 after the init and it will create a fullblown prefix in the MAMBA_ROOT_PREFIX location) and then you can create more envs with micromamba create -n blabla ... and that should just work.

@NegatioN
Copy link

NegatioN commented Oct 15, 2020

That seems interesting, I was creating prefixed envs willy-nilly, instead of using -n 🙂
I'll try that, and report back if things somehow end up not working.

Thanks! 👍

@buhrmann
Copy link

buhrmann commented Nov 12, 2020

Hi, for anybody coming here looking for a basic dockerfile installing micromamba, the following is a minimal setup making micromamba available in each layer and the resulting image:

FROM debian:stable-slim

# Use bash in RUN commands and make sure bashrc is sourced when executing commands with /bin/bash -c
# Needed to have the micromamba activate command configured etc.
SHELL ["/bin/bash", "-c"]
ENV BASH_ENV ~/.bashrc

# Install basic commands and mamba
RUN apt-get update && \
    apt-get install -y ca-certificates wget bash bzip2 && \
    wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba --strip-components=1 && \
    ./micromamba shell init -s bash -p ~/micromamba && \
    apt-get clean autoremove --yes && \
    rm -rf /var/lib/{apt,dpkg,cache,log}

RUN micromamba activate && \
    micromamba install -y -n base python=3.8.6 pip -c conda-forge && \
    rm /root/micromamba/lib/*.a && \
    rm -rf /root/micromamba/pkgs/

I would have loved to use this in our builds, but unless I'm missing something, micromamba is still missing crucial conda feautures (some of which are also not supported by mamba afaik), such as pinned specs, configuration of channel priority, the equivalent of conda env update -f req.yml with pip support etc.

Edit: I've added some commands to cleanup in each layer, reducing the resulting image size from ~600MB to ~230MB. A micromamba clean command would be a good addition.

@wolfv
Copy link
Author

wolfv commented Nov 12, 2020

Hi @buhrmann, yes, indeed, micromamba is still lagging a bit in features. But it's improving at a nice and steady rate, and the 0.7.0 release that just came out should be the best ever :)

Feel free to open an issue over at https://github.com/mamba-org/mamba listing what's missing for your usecase.

@Meao
Copy link

Meao commented Nov 24, 2021

Hi, I tried it all and I still get an error in the end:
curl -Lsvk https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba
source ~/.bash_profile
mv ./micromamba bin/micromamba
source ~/.bash_profile
micromamba activate
./micromamba shell init -s bash -p /home/$USER/micromamba
micromamba shell init -s bash -p /home/$USER/micromamba
source ~/.bash_profile
micromamba activate
mv bin/micromamba ./micromamba
./micromamba shell init -s bash -p ~/micromamba
source ~/.bash_profile
micromamba activate
micromamba install python=3.8 jupyter -c conda-forge

critical File exists: '/Users/myusername/micromamba/conda-meta'

@wolfv
Copy link
Author

wolfv commented Nov 24, 2021

@Meao on macos the default shell is zsh. Maybe you can try to do shell init -s zsh?

@wolfv
Copy link
Author

wolfv commented Nov 24, 2021

and source ~/.zshrc

@Meao
Copy link

Meao commented Nov 24, 2021

Hm, zsh and source ~/.zshrc functioned as I tried it one more time, yet the error after micromamba install python=3.6 jupyter -c conda-forge is still the same.
Curiously, terminal does not keep most of the commands I try in its history as I close and open it, never seen that behaviour berfore.

@wolfv
Copy link
Author

wolfv commented Nov 24, 2021

this line looks weird: mv ./micromamba bin/micromamba.
You might want the other way around?

You could try completely wiping the ~/micromamba folder and start from scratch?

PS these are the original instructiosn. Looks like you mixed them up ?!

curl -Ls https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba
mv bin/micromamba ./micromamba
./micromamba shell init -s zsh -p ~/micromamba
source ~/.zshrc
micromamba activate
micromamba install python=3.6 jupyter -c conda-forge

@Meao
Copy link

Meao commented Nov 24, 2021

curl -Ls https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba
still outputs
SSL certificate problem: certificate has expired

mv bin/micromamba ./micromamba
./micromamba shell init -s zsh -p ~/micromamba
source ~/.zshrc
micromamba activate
still outputs
-bash: micromamba: command not found

@wolfv
Copy link
Author

wolfv commented Nov 24, 2021

The certificate is valid up to December 25 on my machine. If curl isn't downloading anything, then obviously you will not be able to run the following commands. It also looks like you are in fact using bash? Are you on a really old mac?

@Meao
Copy link

Meao commented Nov 24, 2021

curl -Lsvk
works and pulls the file, the machine is not old, it's 2013, just upgraded to Mojave. I'm trying to do what I need with plain mamba now, maybe I'll be luckier that way. I'm also thinking of creating a docker container with a linux inside, yet I don't know how will I be able to open jupyter notebooks I need to view yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment