Environment Management with Pixi
Authors
Setup
Installation
Visual Studio Code (VSCode)
Pixi
Pixi is available for all major operating systems and provides a consistent way to define, reproduce, and run development environments. It can be installed quickly and works seamlessly with the conda-forge ecosystem.
- Installation instructions
- If you have a windows machine
winget install prefix-dev.pixi - Testing installation
pixi --version
In this unit, we will learn how to use Pixi to manage packages and environments. Pixi is a modern package manager built on top of Conda ecosystem principles, but with improved performance, reproducibility, and cross-platform support. It uses a pixi.toml file to define environments and supports tasks for automation. This unit includes instructions for installing Pixi and covers core Pixi commands for creating, managing, and sharing environments.
Section 1: Creating and Managing Environments
With Pixi, environments are defined via a pixi.toml file. This ensures that your environment is reproducible and version-controlled. Pixi uses workspaces (directories with a pixi.toml) and automatically activates environments when you enter them.
| Code | Description |
|---|---|
pixi init |
Initialize a new Pixi project with a pixi.toml |
pixi add python |
Add Python to your environment |
pixi run |
Run commands inside the environment |
pixi shell |
Start a shell with the Pixi environment activated |
pixi info |
Show details about the environment |
pixi list |
List all packages in the environment |
Exercises
-
Initialize a new Pixi environment
-
Initialize Pixi.
-
Open the
pixi.tomlfile and inspect its contents. -
Add Python to the environment.
pixi add python -
Add pip to the environment
-
Start a Pixi shell
-
Verify python is available
python --version -
Verify pip is available
-
Section 2: Installing Python Packages with Pixi
In this section, you’ll learn how to install Python packages into a Pixi-managed environment. Pixi supports two main ways of adding packages:
- Conda-style installation (via
conda-forge): By default. - PyPI-style installation (via
pip): Useful for packages not available onconda-forge.
You can combine both methods in the same environment. This gives you access to a wide range of scientific and general-purpose Python tools.
| Code | Description |
|---|---|
pixi add numpy |
Install numpy from conda-forge |
pixi add matplotlib pandas |
Install multiple packages from conda-forge |
pixi add --pypi package_name |
Install package from PyPI |
pixi add pip |
Add pip support to the environment |
pixi shell |
Enter the environment to run or install additional packages |
pip install seaborn |
Use pip inside Pixi shell for PyPI-only packages |
pixi remove <package> |
Remove a package from the environment |
pixi list |
View all currently installed packages |
Exercises
- Add
numpy,matplotlib - Verify they are installed:
pixi info - Install
streamlitwith--pypipixi add --pypi streamlit - Verify
streamlitis installed - Install
pandaswith--pypiand verify it is installed - Remove
pandasand verify that it is gonepixi remove --pypi pandas
Section 3: Exporting, Sharing, and Reproducing Environments
Unlike Conda, Pixi manages environments via pixi.toml and pixi.lock files. These files define your environment in a reproducible format. Sharing these files with collaborators ensures they can recreate the exact same environment on any platform.
| File | Purpose |
|---|---|
pixi.toml |
Human-editable file that specifies dependencies |
pixi.lock |
Auto-generated file that pins exact versions for reproducibility |
pixi install |
Sync the environment to the lock file |
Exercises
-
Simulate sharing an environment
- Copy only
pixi.tomlandpixi.lockto the new location. - Reproduce the environment in your new folder
- Confirm that
numpyis available and version matches the lock file.
- Copy only