Guidance for developing under a projects managed by pixi...
Expert guidance for using Pixi, a fast conda-based package manager for Python projects.
Help developers effectively use Pixi for managing conda/PyPI dependencies, running commands in isolated environments, and configuring multi-environment projects.
pixi.toml or pixi.lock files# Initialize & install
pixi init [project-name]
pixi install # install default environment
pixi install -e dev # install dev environment
# Add dependencies
pixi add python=3.11 pytorch pandas # conda packages
pixi add --pypi transformers # PyPI packages
pixi add --feature dev pytest ruff # to dev feature
# Run commands
pixi run python script.py # use default env
pixi run -e dev pytest # use dev env
pixi shell # interactive shell
pixi shell -e dev # dev shell
# Tasks
pixi task add lint "ruff check ."
pixi task list
pixi run lint
# Production
pixi run --frozen --no-install train.py
-e <env>: Use specific environment--frozen: Don't update lock file (reproducible)--no-install: Skip installation--feature <name>: Target specific featureDirectory with:
pixi.toml: Configuration (commit this)pixi.lock: Lock file (commit this).pixi/: Environment cache (DON'T commit)Named dependency sets. Use -e flag to select:
pixi run python script.py # default
pixi run -e dev pytest # dev
pixi run -e prod train.py # prod
Reusable dependency groups that compose into environments.
Predefined commands in pixi.toml. Run with pixi run <task-name>.
| Goal | Command |
|---|---|
| First-time setup | pixi install |
| Add package | pixi add <pkg> |
| Run one command | pixi run <cmd> |
| Interactive work | pixi shell |
| Execute task | pixi run <task> |
| Production | pixi run --frozen --no-install |
Prefer conda first (better compatibility, faster):
pixi add numpy pytorch
Use PyPI when needed:
pixi add --pypi transformers
Why conda first? Pixi resolves conda deps first, then PyPI.
[project]
name = "my-project"
channels = ["conda-forge", "pytorch"] # order matters
platforms = ["linux-64", "osx-arm64"]
[dependencies]
python = ">=3.10"
numpy = "*"
pytorch = ">=2.0,<3"
[pypi-dependencies]
transformers = "*"
my-pkg = { path = "./local", editable = true }
Simple:
[tasks]
test = "pytest tests/"
With environment variables:
[tasks.train]
cmd = "python train.py"
env = { CUDA_VISIBLE_DEVICES = "0,1" }
With dependencies:
[tasks]
clean = "rm -rf __pycache__"
test = { cmd = "pytest", depends-on = ["clean"] }
Multi-line:
[tasks.submit]
cmd = """
python train.py \
--config config.yaml \
--output results/
"""
[feature.dev.dependencies]
pytest = "*"
ruff = "*"
[feature.cuda.dependencies]
pytorch-cuda = "12.1"
[environments]
default = []
dev = ["dev"]
gpu = ["cuda"]
dev-gpu = ["dev", "cuda"]
[activation.env]
CUDA_HOME = "/usr/local/cuda"
PROJECT_ROOT = "$PIXI_PROJECT_ROOT"
Dev testing:
pixi run -e dev pytest ./tests
Type checking:
pixi run typecheck
Profiling:
pixi run -e dev nsys profile python train.py
Checks:
channels = [...]?pixi search <pkg>pixi add --pypi <pkg>ā Wrong: python script.py (bare python)
ā
Correct: pixi run python script.py
After merge conflicts:
pixi install # regenerate lock
# or
rm pixi.lock && pixi install
Variables from [activation.env] only work with:
pixi run <cmd>pixi shellNOT with bare python outside pixi.
Use solve-group to isolate environments:
[environments]
default = { solve-group = "group1" }
dev = { features = ["dev"], solve-group = "group1" } # shared
prod = { solve-group = "group2" } # isolated
ā
Conda first, PyPI when needed
ā
Pin critical versions: pytorch = "2.1.*"
ā
Version constraints: python = ">=3.10,<3.12"
ā Don't mix conda + PyPI for same package
ā
Commit pixi.lock
ā
Use --frozen in CI/production
ā Use features to organize deps ā Share solve-groups when possible ā 2-4 environments is ideal
Practical guidance for Pixi. For project-specific patterns, check your CLAUDE.md.