Python: Difference between revisions
imported>Tobias.bora mNo edit summary |
imported>Mausch Add section about micromamba |
||
| Line 203: | Line 203: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Please have a look at more [https://github.com/DavHau/mach-nix/blob/master/examples.md examples]. | Please have a look at more [https://github.com/DavHau/mach-nix/blob/master/examples.md examples]. | ||
=== micromamba === | |||
Install the <code>micromamba</code> package (currently in <code>nixpkgs-unstable</code> only). | |||
You can create environments and install packages as [https://github.com/mamba-org/mamba#micromamba documented by micromamba] e.g. | |||
<syntaxhighlight lang="shell"> | |||
micromamba create -n my-environment python=3.7 numpy=1.21.0 -c conda-forge | |||
</syntaxhighlight> | |||
To activate an environment you will need a [https://nixos.org/manual/nixpkgs/stable/#sec-fhs-environments FHS environment] e.g.: | |||
<syntaxhighlight lang="shell"> | |||
$ nix-shell -E 'with import <nixpkgs> {}; (pkgs.buildFHSUserEnv { name = "fhs"; }).env' | |||
$ eval "$(micromamba shell hook -s bash)" | |||
$ micromamba activate my-environment | |||
$ python | |||
>>> import numpy as np | |||
</syntaxhighlight> | |||
Eventually you'll probably want to put this in a shell.nix so you won't have to type all that stuff every time e.g.: | |||
<syntaxhighlight lang="shell"> | |||
let | |||
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/79b7bd36a358f90ffd287b061132641175b8d31e.tar.gz") {}; | |||
fhs = pkgs.buildFHSUserEnv { | |||
name = "my-fhs-environment"; | |||
targetPkgs = _: [ | |||
pkgs.micromamba | |||
]; | |||
profile = '' | |||
set -e | |||
eval "$(micromamba shell hook -s bash)" | |||
export MAMBA_ROOT_PREFIX=${builtins.getEnv "PWD"}/.mamba | |||
micromamba create -q -n my-mamba-environment | |||
micromamba activate my-mamba-environment | |||
micromamba install --yes -f conda-requirements.txt -c conda-forge | |||
set +e | |||
''; | |||
}; | |||
in fhs.env | |||
</syntaxhighlight> | |||
=== conda === | === conda === | ||