| name | pixi |
| description | Comprehensive guide for using Pixi, a fast and reproducible package management tool for Python, Rust, C/C++, and other languages. Use when (1) Managing Python project dependencies and environments, (2) Setting up reproducible development environments with conda and PyPI packages, (3) Creating cross-platform task runners and build pipelines, (4) Managing multiple isolated environments for testing and development, (5) Installing and managing global CLI tools, (6) Building and packaging conda packages, (7) Working with mixed conda and PyPI dependencies, (8) Setting up CI/CD pipelines with reproducible environments |
| metadata | {"short-description":"Fast and reproducible package management tool"} |
Pixi Package Manager
Pixi is a fast, modern, and reproducible package management tool that combines conda and PyPI package management with built-in task running and environment management.
Quick Start
Installation
curl -fsSL https://pixi.sh/install.sh | sh
powershell -ExecutionPolicy Bypass -c "irm -useb https://pixi.sh/install.ps1 | iex"
Restart your terminal after installation.
Create a Project
pixi init my-project
cd my-project
pixi add python
pixi add numpy
pixi add --pypi requests
pixi run python -c "import numpy; print(numpy.__version__)"
pixi shell
Core Workflows
Project Management
Initialize workspace:
pixi init [project-name]
pixi init --format pyproject
Add dependencies:
pixi add python ">=3.11"
pixi add numpy pandas
pixi add --pypi requests flask
pixi add --feature test pytest
pixi add --platform linux-64 glibc
Remove dependencies:
pixi remove numpy
pixi remove --feature test pytest
Update dependencies:
pixi update
pixi upgrade
pixi lock
Install environment:
pixi install
pixi install --environment test
pixi install --frozen
pixi install --locked
Running Commands
Execute tasks or commands:
pixi run python script.py
pixi run --environment test pytest
pixi run task-name
pixi run --environment dev task-name
Activate shell:
pixi shell
pixi shell --environment test
One-off commands:
pixi exec python --version
pixi exec --spec "python=3.12" python --version
Task Management
Define tasks in pixi.toml:
[tasks]
hello = "echo Hello World"
build = { cmd = "cargo build", depends-on = ["fmt", "lint"] }
run = { cmd = "python main.py", env = { DEBUG = "true" } }
compile = {
cmd = "gcc -o output input.c",
inputs = ["input.c"],
outputs = ["output"]
}
greet = {
cmd = "echo Hello, {{ name }}!",
args = [{ arg = "name", default = "World" }]
}
Manage tasks:
pixi task add build "cargo build"
pixi task add test "pytest" --depends-on build
pixi task add lint "ruff check ." --feature dev
pixi task list
pixi task remove build
Run tasks with arguments:
pixi run greet Alice
pixi run build production linux-64
Multiple Environments
Using features and environments:
[dependencies]
python = ">=3.11"
[feature.test.dependencies]
pytest = "*"
pytest-cov = "*"
[feature.lint.dependencies]
ruff = "*"
mypy = "*"
[feature.dev.dependencies]
ipython = "*"
[environments]
default = []
test = ["test"]
dev = ["test", "lint", "dev"]
Work with environments:
pixi add --feature test pytest
pixi run --environment test pytest
pixi shell --environment dev
pixi list --environment test
pixi install --environment prod
Solve groups (ensure shared versions):
[environments]
prod = { features = [], solve-group = "prod" }
test-prod = { features = ["test"], solve-group = "prod" }
Global Tools
Install global CLI tools:
pixi global install gh nvim ipython btop ripgrep
pixi global install terraform ansible k9s
Manage global installations:
pixi global list
pixi global add nvim ripgrep
pixi global update
pixi global uninstall gh
pixi global sync
Manifest Structure
Basic pixi.toml:
[project]
name = "my-project"
version = "0.1.0"
channels = ["conda-forge"]
platforms = ["linux-64", "osx-64", "win-64"]
[dependencies]
python = ">=3.11"
numpy = ">=1.21"
[pypi-dependencies]
requests = ">=2.25"
fastapi = { version = ">=0.100", extras = ["all"] }
[tasks]
test = "pytest"
dev = "uvicorn main:app --reload"
[environments]
default = ["test"]
Package specifications:
python = ">=3.11,<3.13"
numpy = "==1.21.0"
pytorch = "2.0.*"
pytorch = { version = "2.0.*", channel = "pytorch" }
numpy = { version = ">=1.21", build = "py311*" }
pandas = { version = ">=1.0", extras = ["dataframe", "sql"] }
package = { git = "https://github.com/user/repo.git", rev = "abc123" }
my-pkg = { path = ".", editable = true }
Configuration
Project configuration (.pixi/config.toml):
pinning-strategy = "semver"
[shell]
change-ps1 = true
Global configuration (~/.pixi/config.toml):
default-channels = ["conda-forge"]
[pypi-config]
index-url = "https://pypi.org/simple"
extra-index-urls = ["https://custom-index.com/simple"]
[proxy-config]
https = "http://proxy.example.com:8080"
Configure via CLI:
pixi config set pinning-strategy semver
pixi config set shell.change-ps1 false
pixi config list
pixi config edit
Lockfile Management
Understanding lockfiles:
pixi.lock ensures reproducible environments
- Contains exact package versions and build info
- Should be committed to version control
- Automatically updated when dependencies change
Lockfile commands:
pixi lock
pixi install --frozen
pixi install --locked
Common Patterns
Python Project Setup
[project]
channels = ["conda-forge"]
platforms = ["linux-64", "osx-64", "win-64"]
[dependencies]
python = ">=3.11"
[pypi-dependencies]
fastapi = "*"
uvicorn = { extras = ["standard"], version = "*" }
my-package = { path = ".", editable = true }
[feature.test.dependencies]
pytest = "*"
pytest-asyncio = "*"
[tasks]
dev = "uvicorn main:app --reload"
test = "pytest"
lint = "ruff check . && mypy ."
[environments]
default = ["test", "lint"]
C/C++ Project
[dependencies]
cmake = "*"
ninja = "*"
[target.linux-64.dependencies]
gcc_linux-64 = "*"
[target.osx-64.dependencies]
clang_osx-64 = "*"
[tasks]
configure = "cmake -S . -B build -G Ninja"
build = { cmd = "cmake --build build", depends-on = ["configure"] }
test = { cmd = "ctest --test-dir build", depends-on = ["build"] }
Multi-Version Testing
[feature.py39.dependencies]
python = "3.9.*"
[feature.py310.dependencies]
python = "3.10.*"
[feature.py311.dependencies]
python = "3.11.*"
[environments]
py39 = ["py39", "test"]
py310 = ["py310", "test"]
py311 = ["py311", "test"]
Platform-Specific Configuration
[target.linux-64.dependencies]
glibc = "2.28"
[target.osx-arm64.dependencies]
mlx = "*"
[target.win-64.dependencies]
msmpi = "~=10.1.1"
[target.unix.tasks]
clean = "rm -rf build/"
[target.win.tasks]
clean = "rmdir /s /q build"
Environment Activation
Activation scripts:
[activation]
scripts = ["setup.sh"]
env = {
MY_VAR = "value",
PATH = "$PIXI_PROJECT_ROOT/bin:$PATH"
}
[target.win-64.activation]
scripts = ["setup.bat"]
In shell:
pixi shell
Utility Commands
pixi info
pixi list
pixi list --environment test
pixi tree
pixi tree --invert package
pixi search numpy
pixi clean
pixi clean --environment test
pixi clean cache
pixi auth login
pixi auth logout
pixi completion --shell bash > ~/.bash_completion
pixi completion --shell zsh > ~/.zsh_completion
Troubleshooting
Environment out of sync:
pixi install
pixi reinstall
Lockfile issues:
rm pixi.lock
pixi lock
Clear cache:
pixi clean cache
Check configuration:
pixi info -vvv
pixi config list
Best Practices
- Commit lockfiles: Always commit
pixi.lock to version control
- Use features: Organize dependencies by purpose (test, lint, dev)
- Use solve-groups: When environments need shared versions
- Task caching: Specify
inputs and outputs for faster rebuilds
- Platform-specific: Use
target tables for cross-platform differences
- Prefer conda: Use conda packages when available (more stable, binary deps)
- Editable installs: Use
editable = true for local packages
References
For detailed information, see: