Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wolfv
Last active March 10, 2024 15:28
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wolfv/fe1ea521979973ab1d016d95a589dcde to your computer and use it in GitHub Desktop.
Save wolfv/fe1ea521979973ab1d016d95a589dcde to your computer and use it in GitHub Desktop.
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
}
@xiamaz
Copy link

xiamaz commented Jun 11, 2022

I have created an automatic update script if anyone is interested:

#!/usr/bin/bash

UPDATE_URL="https://api.anaconda.org/release/conda-forge/micromamba/latest"

function version_gt() {
	test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1";
}

install_micromamba() {
	download_url="https:$(jq -r ".download_url" <<< $1)"
	echo $download_url
	curl -Ls "$download_url" | tar -xvj -C $(dirname $MAMBA_EXE) "bin/micromamba"
	# "$MAMBA_EXE"
}

if [ -z $MAMBA_EXE ]; then
	echo "MAMBA_EXE is unset. Install MAMBA first!"
	exit
fi

arch="$(uname -m)"
case `uname -s` in
	Linux)
		platform="linux"
		;;
	Darwin)
		platform="osx"
		;;
	*)
		platform="unknown"
		;;
esac
info_json=$(curl -s "$UPDATE_URL" | jq ".distributions | .[] | select((.attrs.arch==\"$arch\") and (.attrs.platform==\"$platform\"))")

available_version=$(jq -r ".version" <<< "$info_json")
installed_version=$(micromamba --version)

if version_gt $available_version $installed_version; then
	echo "micromamba newer version $available_version available. (installed: $installed_version)"
	read -p "Upgrade? (yN) " resp
	case "$resp" in
		y|Y)
			echo "Updating micromamba"
			install_micromamba "$info_json"
			;;
		*)
			echo "Cancelling upgrade..."
			;;
	esac
else
	echo "micromamba version $available_version available. (installed: $installed_version)"
fi

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