We need something better than pip
β and that's where uv comes in. Itβs a fast Python package manager and task runner that replaces pip
, venv
, and even parts of poetry
, without the extra overhead.
Though previously I wrote Do not use 'pip freeze' and Best way to create requirements.txt. You can read them...
π First install uv
You can find the installation instructions for uv
here
π§ uv init
: Instant Project Setup
uv init
This command creates a boilerplate pyproject.toml
and sets up your .venv
β no manual steps needed. It automatically detects your Python version and prepares a minimal project environment.
β uv add: Add Dependencies Instantly
Need a package like rich?
uv add rich
This adds it to your pyproject.toml
, installs it, and updates your uv.lock
. No need to touch requirements.txt
.
Example usage with rich:
from rich import print
print("[bold green]Hello from UV-powered project![/bold green]")
π uv run: Run with Environment
Instead of manually activating .venv
, use:
uv run main.py
This runs your app inside the managed environment automatically.
Yes, you can still run with python main.py
, but that means you'll have to activate .venv
manually:
source .venv/bin/activate
π After Clone/Pull a UV based project
First run
uv venv
and then install all packages from pyproject.toml
uv sync
π Want More?
Thereβs more you can do: uv pip
, uv pip freeze
, uv sync --update
, and more. You can even change Python versions or set a specific version in .python-version
β check it out in their docs.
Top comments (0)