forked from linux/documentation
117 lines
3.7 KiB
Markdown
117 lines
3.7 KiB
Markdown
# Pixi / Micromamba
|
|
|
|
Micromamba and Pixi are package managers for conda (and pip/pypi) packages that can be used to easily create tailored Python environments. Micromamba is a drop-in replacements for conda and can be used in a similar way. Pixi has a slightly different usage pattern than micromamba. They both have none of the licensing restrictions that Anaconda has and point to the free and unproblematic conda-forge channel by default.
|
|
|
|
More details on these package managers can be found at:
|
|
|
|
- https://mamba.readthedocs.io/en/latest/
|
|
- https://pixi.prefix.dev/latest/
|
|
|
|
As conda-forge is not accessible from certain networks within PSI we have a local caching mirror of the conda-forge channel available at https://conda.psi.ch. Please use this channel as the default channel for your conda environments at PSI!
|
|
|
|
|
|
## Installation
|
|
|
|
We provide RPM packages for both and the commands can easily be installed like this:
|
|
|
|
```yaml
|
|
# Install micromamba / pixi
|
|
base::pkg_group::extra:
|
|
- "micromamba"
|
|
- "pixi"
|
|
|
|
base::package_groups:
|
|
- "extra"
|
|
```
|
|
|
|
After installing the package(s) the command(s) (`micromamba`, `pixi`) will be available via the standard PATH.
|
|
|
|
To configure the global channels for micromamba and pixi, you can create a configuration file at `/etc/conda/.condarc` with the following content:
|
|
|
|
```yaml
|
|
channels:
|
|
- https://conda.psi.ch/get/conda-forge
|
|
|
|
channel_priority: strict
|
|
```
|
|
|
|
The following hiera configuration can be used to create this file:
|
|
|
|
```yaml
|
|
# Create conda config file with global channels
|
|
files::files:
|
|
/etc/conda/.condarc:
|
|
content: |
|
|
channels:
|
|
- https://conda.psi.ch/get/conda-forge
|
|
channel_priority: strict
|
|
```
|
|
|
|
There are additional channel that are mirrored from anaconda.org which can be configured as follows:
|
|
- https://conda.psi.ch/get/paulscherrerinstitute
|
|
- https://conda.psi.ch/get/slsdetectorgroup
|
|
|
|
## Usage
|
|
|
|
### Micromamba
|
|
|
|
To initialize micromamba for your shell, you can run the following command:
|
|
|
|
```bash
|
|
micromamba shell init
|
|
```
|
|
|
|
This will add the necessary initialization code to your shell configuration file (e.g., `~/.bashrc` for bash). After that, you can create and manage your conda environments using micromamba commands, which are similar to conda commands.
|
|
|
|
!!! note
|
|
You only need to run the `micromamba shell init` command once. After that, you can use micromamba commands in your shell without any additional setup.
|
|
|
|
After running the initialization command you need to restart your shell or source your shell configuration file (e.g., `source ~/.bashrc`) for the changes to take effect.
|
|
|
|
To create a new environment called `myenv` with Python 3.14, you can run:
|
|
|
|
```bash
|
|
micromamba create -n myenv python=3.14
|
|
```
|
|
|
|
Afterwards the environment can be activated and used with:
|
|
|
|
```bash
|
|
# activate this environment
|
|
micromamba activate myenv
|
|
|
|
# Or execute a single command in this environment without activating it
|
|
micromamba run -n myenv mycommand
|
|
```
|
|
|
|
### Pixi
|
|
|
|
Pixi has a slightly different usage pattern than micromamba. Pixi is a project-centric package manager like `cargo` (Rust) or `npm` (Node). You define a pixi.toml in your "project", and it manages environments per project.
|
|
To initialize a new pixi project, you can run the following command in your project directory:
|
|
|
|
```bash
|
|
pixi init my_workspace
|
|
|
|
# To use initialize the workspace to use the PSI internal caching mirrors use:
|
|
pixi init my_workspace --channel https://conda.psi.ch/get/conda-forge
|
|
```
|
|
|
|
To add a dependency to your project, you can run:
|
|
|
|
```bash
|
|
cd my_workspace
|
|
pixi add numpy
|
|
```
|
|
|
|
Activate the environment for this project with:
|
|
|
|
```bash
|
|
pixi shell
|
|
```
|
|
|
|
To leave the shell simply exit it with `exit` or `Ctrl+D`. You can also run a single command in the project environment without activating the shell with:
|
|
|
|
```bash
|
|
pixi run mycommand
|
|
```
|