Why Pixi?
If you have worked with Python before,
you might have heard of tools like pip, conda, or venv.
Pixi provides several advantages over these traditional tools:
Reproducibility: Pixi uses a “lock file” (
pixi.lock) to ensure that the exact same versions of all packages can be reliably installed by different users on different machines. This prevents “it works on my machine” bugs.Speed: Pixi is built in Rust and is exceptionally fast at resolving and installing packages.
Multi-language: While excellent for Python, Pixi can also manage packages from other languages and systems (like C++, R, or command-line tools).
Isolated Environments: Pixi creates a separate environment for each project, so you don’t have to worry about one project’s requirements breaking another.
Installing Pixi
The easiest way to install Pixi is using their official installer script.
On macOS and Linux including the Alliance machines:
$ curl -fsSL https://pixi.sh/install.sh | bash
On Windows (PowerShell):
iwr -useb https://pixi.sh/install.ps1 | iex
Autocompletion
Having Pixi autocomplete its sub-commands,
option flags,
environment names,
etc.
when you hit Tab is very convenient.
To enable that for bash,
add the following line to your $HOME/.bashrc file:
eval "$(pixi completion --shell bash)"
For other shells, please see the Pixi Autocompletion docs.
After installation, please restart your terminal session to finalize the installation.
Basic Usage
Once Pixi is installed, here are the most common commands you will use.
Installing an Environment
After you have cloned a Pixi-powered repository, navigate to your project folder and run:
$ pixi install
This downloads the packages required by the project and installs them in an isolated environment for you to use.
Adding Packages
To add a package (like numpy or pandas) to your project:
$ pixi add numpy
This will update your pixi.toml and pixi.lock files,
and automatically install the package into the project-specific environment.
Please ensure that you commit the changes your pixi.toml and pixi.lock files,
and push them to GitHub so that you maintain an accurate record of you working environment.
Running Commands
To run a script or a command within your Pixi environment:
$ pixi run python my_script.py
Using the Pixi Shell
If you are doing a lot of command-line work and don’t want to have to type pixi run before every command, you can work inside the environment interactively by doing:
$ pixi shell
This “activates” the environment in your current terminal session.
You can exit the shell by typing exit.
Pixi Details
Pixi has many more features and capabilities. Most MOAD users will use Pixi by cloning Pixi-powered repositories from GitHub and running commands with pixi run, but Pixi also has extensive support for Python package development and other software development tasks. The documentation has excellent “Getting Started” sections and tutorials, as well as detailed command-line interface (CLI) reference docs.