Pixi: A clever way to manage the Python environment

by SkillAiNest

Pixi: A clever way to manage the Python environmentPixi: A clever way to manage the Python environment
Photo by author

# Introduction

Python is now one of the most popular languages ​​with applications in software development, data science, and machine learning. Its flexibility and rich collection of libraries make it a favorite among developers in almost every field. However, working with multiple Python environments can still be a significant challenge. This is the place Pixie comes to the rescue. It identifies the real challenges of reproducibility and transport at all levels of development. Teams working on machine learning, web applications, or data pipelines get a consistent environment, streamlined continuous integration/continuous deployment (CI/CD) workflows, and rapid onboarding. With its isolated per-project design, it brings a modern and reliable approach to managing Python environments. This article explores how to manage a Python environment using Pixi.

# Why Environmental Management Matters

A beginner can find it easier to manage a Python environment with tools venv or virtualenv. However, as projects grow in scope, these approaches reveal their limitations. Often, you find yourself reinstalling the same packages over and over again for different projects, which becomes repetitive and inefficient. Additionally, trying to keep dependencies in sync with your colleagues or with production servers can be difficult. Even a small version mismatch can cause the project to fail. Sharing or replicating environments can become increasingly unmanageable, leading to situations where one setup of dependencies works on one machine but breaks on another. These environmental problems can slow development, create frustration and introduce unnecessary inconsistencies that hinder productivity.

Pixi Workflow: From Zero to Reproducible EnvironmentPixi Workflow: From Zero to Reproducible Environment
Pixi Workflow: From Zero to Reproducible Environment | Photo by editor

# A step-by-step guide to using PIXI

// 1. Install Pixi

For macOS/Linux:
Open your terminal and run:

# Using curl
curl -fsSL  | sh

# Or with Homebrew (macOS only)
brew install pixi

Now, add pixie to your path:

# If using zsh (default on macOS)
source ~/.zshrc

# If using bash
source ~/.bashrc

For Windows:
Open PowerShell as administrator and run:

powershell -ExecutionPolicy ByPass -c "irm -useb  | iex"

# Or using winget
winget install prefix-dev.pixi

// 2. Start your project

Create a new workspace by running the following command:

pixi init my_project
cd my_project

Output:

✔ Created /Users/kanwal/my_project/pixi.toml

pixi.toml file is the configuration file for your project. This tells Pixie how to set up your environment.

// 3. Create pixi.toml

Currently yours pixi.toml It looks something like this:

(workspace)
channels = ("conda-forge")
name = "my_project"
platforms = ("osx-arm64")
version = "0.1.0"

(tasks)

(dependencies)

You need to edit it to include the Python version and PYPI dependencies:

(workspace)
name = "my_project"
channels = ("conda-forge")
platforms = ("osx-arm64")
version = "0.1.0"

(dependencies)
python = ">=3.12"

(pypi-dependencies)
numpy = "*"
pandas = "*"
matplotlib = "*"

(tasks)

Let’s understand the file structure:

  • (Workspace): It contains general project information, including project name, version, and supported platforms.
  • (dependency): In this section, you specify basic dependencies such as the Python version.
  • (depends on PYPI): You specify Python packages to install from PYPI (eg numpy And pandas) Pixi will automatically create a virtual environment and install this package for you. For example, numpy = "*" Installs the latest compatible version of Numpy.
  • (work): You can define custom commands that you want to run in your project, for example, to test scripts or script execution.

// 4. Install your environment

Run the following command:

Pixi will create a virtual environment with all the specified dependencies. You should see a confirmation like:

✔ The default environment has been installed.

// 5. Activate the environment

You can activate the environment by running a simple command:

Once activated, all Python commands you run in this shell will use the isolation environment created by Pixi. Your terminal prompt will change to enable your workspace:

(my_project) kanwal@Kanwals-MacBook-Air my_project %

Within this shell, all installed packages are available. You can also disable the environment using the following command:

// 6. Add/update dependencies

You can also add new packages from the command line. For example, to add Scipy, run the following command:

PIXI will update the environment and ensure that all dependencies are synchronized. The output will be:

✔ Added scipy >=1.16.3,<2

// 7. Run your Python scripts

You can also create and run your own Python scripts. Create a simple python script, my_script.py:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import scipy


print("All packages loaded successfully!")

You can run it as follows:

This will produce:

All packages loaded successfully!

// 8. Share your environment

To share your environment, commit first pixi.toml And pixi.lock Version control:

git add pixi.toml pixi.lock
git commit -m "Add Pixi project configuration and lock file"
git push

After that, you can reproduce the environment on another machine:

git clone 
cd 
pixi install

Pixi will reuse the exact environment and recreate it pixi.lock File

# wrap up

PIXI provides a smart approach by integrating advanced dependency management with the Python ecosystem to improve reproducibility, portability and speed. Because of its simplicity and reliability, Pixi is becoming an essential tool in the toolbox of modern Python developers. You can also check Pixie Documents to know more.

Kanwal Mehreen is a machine learning engineer and technical writer with a deep passion for data science and the intersection of AI with medicine. He co-authored the eBook “Maximizing Productivity with ChatGPT.” As a 2022 Google Generation Scholar for APAC, she champions diversity and academic excellence. He has also been recognized as a Teradata Diversity in Tech Scholar, a MITACS Globallink Research Scholar, and a Harvard Wicked Scholar. Kanwal is a passionate advocate for change, having founded the Fame Code to empower women in stem fields.

You may also like

Leave a Comment

At Skillainest, we believe the future belongs to those who embrace AI, upgrade their skills, and stay ahead of the curve.

Get latest news

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

@2025 Skillainest.Designed and Developed by Pro