UV package management

I learned uv recently when seeing lots of openai usage during their presentation so I begin to look into it. It is very fast and powerful.

1. Context: Why Choose uv Over Conda?

Traditional Python environment managers like conda bundle both Python distributions and packages, resulting in large downloads, heavy disk usage, and notoriously slow “Solving environment” steps that can take minutes or more uwu. Conda’s solver must consider hundreds of packages and versions, which grows the search space and drags performance down (✿◠‿◠).
By contrast, uv is written in Rust and resolves and installs dependencies in milliseconds—often 10–100× faster than pip! It ships as a single static binary with no Python or Rust prerequisites, so you can just curl it down and go. With uv you get:

  • A unified CLI replacing pip, pip-tools, pipx, poetry, pyenv, virtualenv, and more
  • A universal lockfile for reproducible installs across machines
  • Cross‑platform support (macOS, Linux, Windows) with global caching to dedupe deps
  • Blazing‑fast dependency resolution and install times 🌟

2. Basic Usage: Init, Install, Sync, and Python Version Management 🐍

2.1 Initializing a New Project

Getting started is as simple as:

$ uv init myproject
Initialized project `myproject` at `/path/to/myproject`
$ cd myproject

This creates a new directory with a default uv.toml and sets up project scaffolding—no separate virtualenv or pyenv steps needed uwu.

2.2 Installing Dependencies

To add a package (e.g. ruff for linting):

$ uv add ruff
Creating virtual environment at: .venv
Resolved 1 package in 6ms
Installed 1 package in 2ms
 + ruff==0.5.4

Under the hood, uv automatically creates or reuses a .venv folder and invokes its fast resolver; you get feedback on resolution and install times, usually under 10 ms (´ ∀ `)♡

2.3 Synchronizing Environments

After locking your dependencies:

$ uv lock
Resolved 2 packages in 0.33ms

You can replicate the exact environment elsewhere with:

$ uv sync
Resolved 2 packages in 0.70ms
Audited 1 package in 0.02ms

All packages defined in your lockfile are installed atomically, so new machines match yours perfectly—no more “it works on my machine” woes uwu.

2.4 Installing a Specific Python Version

uv also makes it easy to install and manage multiple Python interpreters:

Install the latest Python

$ uv python install

Downloads and installs the most recent CPython build automatically.

Install a specific version

$ uv python install 3.12

Fetches and sets up Python 3.12 in uv’s global cache in just a few seconds ✧(。•̀ᴗ-)✧

Install multiple versions at once

$ uv python install 3.11 3.12

List available and installed versions

$ uv python list

Shows both the Python versions already in your cache and those you could download, helping you verify your setup at a glance.

Pin your project’s Python version

$ uv python pin 3.12

Generates a .python-version file in your project root, ensuring consistency across machines.

Specify Python when initializing

$ uv init myproject --python 3.12

If 3.12 isn’t installed yet, uv will download it and create the new project with the specified interpreter.

2.5 Activate the envirment

Before running your code, you’ll want to activate the .venv that uv created:

On macOS/Linux

$ source .venv/bin/activate

Once activated, your prompt should show (.venv) and you can run Python or any installed tools directly:

(.venv) $ python --version
Python 3.12.x
(.venv) $ uv run pytest

Deactivating is just as easy:

(.venv) $ deactivate

Activation ensures you’re using the exact interpreter and dependencies defined by uv, keeping everything reproducible and isolated uwu.

3. Summary: A New Era of Efficiency ✨

uv is the next‑generation Python package and environment manager that finally answers the call for speed and simplicity. By consolidating multiple tools into one Rust‑powered binary, it slashes setup and install times, reduces disk overhead with a global cache, and provides a familiar, pip‑compatible CLI. If you’ve been hindered by conda’s bulk and sluggish solver, give uv a spin—your workflows will thank you! uwu

comments powered by Disqus