Package Management

Contents

Package Management#

uv#

Task

Command

Create new application project

uv init proj_name

Create new libary project

uv init --lib proj_name

Install specific version of python

uv python install 3.12

Add dependency

uv add django requests "pandas>=2.3"

Remove package

uv remove django

List packages

uv pip list

See package dependency tree

uv tree

Run a cli tool like Ruff

uv run tool ruff (or uvx ruff)

Update uv version to latest

uv self update

Run a script

uv run script.py

uv supports two templates for projects:

  • Applications uv init proj_name: for web servers, scripts, and command-line interfaces.

  • Libraries uv init --lib proj_name: intended to be built and distributed (e.g., uploaded to PyPI).

Install local pyproject.toml in editable mode with dev dependencies: uv pip install -e .

Activate the virtual environment:

  • Windows (cmd): .venv\Scripts\activate

  • Windows (PowerShell): .\.venv\Scripts\Activate.ps1

  • macOS/Linux: source .venv/bin/activate

Optional dependencies ([project.optional-dependencies]) are extras that get published and can be installed via pip install package[extra].

  • Install a single extra: uv pip install -r pyproject.toml --extra dev

  • Install all extras: uv pip install -r pyproject.toml --all-extras

Dependency groups ([dependency-groups]) are development-only groups (tests, linters, build tools, etc.) that do not get published to PyPI.

  • Install a single dependency-group: uv pip install --group dev

  • Install all dependency-groups: uv pip install --all-groups

Mamba#

Task

Command

Create a new environment

mamba create --name myenv

Create a new environment with specific Python

mamba create --name myenv python=3.9

Activate an environment

mamba activate myenv

Deactivate an environment

mamba deactivate

Install a package

mamba install numpy

Install a package from a specific channel

mamba install -c mamba-forge pandas

Update a package

mamba update scipy

Remove a package

mamba remove matplotlib

Remove an environment

mamba remove --name myenv --all

List packages

mamba list

List all environments

mamba env list

Export environment to a file

mamba env export > environment.yml

Create an environment from a file

mamba env create -f environment.yml

Update mamba to the latest version

mamba update mamba