Managing Python environments and dependencies can be one of the most frustrating aspects of Python development. Enter conda and Pixi—two powerful tools that, when used together, create a streamlined workflow for managing packages, environments, and project dependencies. This guide will get you up and running with both tools in minutes.

What Are Conda and Pixi?

Conda is a cross-platform package manager and environment management system that handles not just Python packages, but also system-level dependencies, binary packages, and packages from multiple programming languages.

Pixi is a modern, fast package management tool built on top of the conda ecosystem. It’s designed to be a drop-in replacement for traditional Python workflow tools, offering lightning-fast dependency resolution and an intuitive command-line interface.

Why Use Conda + Pixi Together?

The combination of conda and Pixi gives you:

  • Fast dependency resolution: Pixi uses modern algorithms for quick package resolution
  • Cross-platform compatibility: Works seamlessly on Windows, macOS, and Linux
  • Reproducible environments: Lock files ensure consistent environments across teams
  • Binary package support: Handle complex dependencies like scientific libraries with ease
  • Multi-language support: Manage Python, R, Julia, and other language packages in one place

Installing Conda

Option 1: Miniconda (Recommended)

Miniconda provides a minimal conda installation:

# Verify installation
conda --version

Option 2: Anaconda

For a full scientific Python distribution:

Installing Pixi

Pixi can be installed using various methods:

Using the install script (Linux/macOS)

curl -fsSL https://pixi.sh/install.sh | bash

Using Homebrew (macOS)

brew install pixi

Using Conda

conda install -c conda-forge pixi

To verify installation, use the prompt:

pixi --version

Quick Start: Your First Project

Follow these simple steps to create your first project with conda and Pixi.

1. Initialize a New Project

mkdir my-data-project
cd my-data-project
pixi init

This creates a pixi.toml file—the heart of your project configuration.

2. Add Dependencies

First, use Pixi to add your preferred version of Python and the packages you plan to use. For a data analysis project, for example, consider pandas, NumPy, and matplotlib. Then add any known dependencies.

# Add Python packages
pixi add python=3.11
pixi add pandas numpy matplotlib

# Add development dependencies  
pixi add --dev pytest black isort

3. Install Dependencies

pixi install

4. Run Your Project

To run your project, you can activate the environment and run commands or start a shell in the environment.

# Activate the environment and run commands
pixi run python your_script.py

# Or start a shell in the environment
pixi shell

Understanding pixi.toml

The pixi.toml file is your project’s configuration center:

[project]
name = "my-data-project"
version = "0.1.0"
description = "A sample data science project"
channels = ["conda-forge"]
platforms = ["linux-64", "osx-64", "win-64"]

[dependencies]
python = ">=3.11,<3.12" pandas = ">=2.0"
numpy = ">=1.24"
matplotlib = ">=3.7"

[dev-dependencies]
pytest = "*"
black = "*"
isort = "*"

[tasks]
test = "pytest tests/"
format = "black . && isort ."
lint = "black --check . && isort --check-only ."

The .toml file offers all the operational details of your project.

Essential Commands

Here are some essential commands to keep handy when developing with conda and Pixi.

Environment Management

# Create and activate environment
pixi install
pixi shell

# Show environment info
pixi info

# List installed packages
pixi list

Package Management

# Add packages
pixi add package-name
pixi add --dev dev-package

# Remove packages
pixi remove package-name

# Update packages
pixi update

Running Tasks

Running tasks programmatically with Python offers significant benefits, primarily to automate repetitive and time-consuming manual work, which enhances efficiency, reduces human error, and allows for more complex, scheduled workflows.

# Run predefined tasks
pixi run test
pixi run format
pixi run lint

# Run custom commands
pixi run python -c "import pandas; print(pandas.__version__)"

Working with Existing Conda Environments

You can migrate existing conda environments to Pixi by exporting your conda environment, initializing a Pixi project and adding your environment yaml file to your pixi manifest:

# Export existing conda environment
conda env export > environment.yml

# Initialize pixi project and import
pixi init
pixi add --manifest-path environment.yml

Best Practices

1. Lock File Management

Always commit your pixi.lock file to version control—it ensures reproducible environments across your team.

2. Use Specific Channels

Be explicit about conda channels in your pixi.toml:

channels = ["conda-forge", "bioconda", "pytorch"]

3. Platform Specification

Define target platforms upfront:

platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]

4. Organize Dependencies

Separate runtime and development dependencies:

pixi add pandas numpy          # Runtime
pixi add --dev pytest black    # Development

5. Use Tasks for Common Workflows

Define common commands as tasks in pixi.toml:

[tasks]
start = "python main.py"
test = "pytest tests/ -v"
clean = "find . -type f -name '*.pyc' -delete"

Troubleshooting Common Issues

Slow Dependency Resolution

Use mamba solver for faster dependency resolution:

pixi config set solver mamba

Package Conflicts

Check for conflicts in your packages:

# Check for conflicts
pixi check

# Update lock file
pixi update --dry-run

Environment Issues

If you’re dealing with environment issues, consider cleaning and rebuilding your environment:

# Clean and rebuild environment
rm -rf .pixi/
pixi install

Advanced Features

Multiple Environments

Define different environments for different use cases:

[environments]
default = ["main"]
test = ["main", "test"]
docs = ["main", "docs"]

[feature.test.dependencies]
pytest = "*"
coverage = "*"

[feature.docs.dependencies]
sphinx = "*"

Custom Channels

Add private or custom conda channels:

[project]
channels = ["conda-forge", "https://my-private-channel.com"]

Conclusion

Conda and Pixi together provide a modern, fast, and reliable solution for Python environment management. The combination offers the robustness of the conda ecosystem with the speed and user-friendliness of Pixi’s modern tooling.

Start with a simple project, experiment with the commands shown in this guide, and gradually adopt more advanced features as your projects grow in complexity. Your future self (and your teammates) will thank you for the reproducible, well-managed environments.

Next Steps

Happy coding!