Python Tutorial: UV - A Faster, All-in-One Package Manager to Replace Pip and Venv
Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
UV consolidates pip, venv, lockfile creation, and pipx-style tool installation into one workflow with commands like uv add, uv run, and uv tool install.
Briefing
UV is positioned as a single, faster replacement for several core Python workflow tools—installing packages, creating and managing virtual environments, generating lock files, and installing command-line tools—while also making environments reproducible and easier to run without manual activation. Built and maintained by Astral (the same team behind Ruff), UV aims to collapse the usual pip + venv + lockfile + pipx toolchain into one interface, with speed attributed to its Rust implementation.
The tutorial starts with installation options, then moves into a side-by-side comparison of the “old way” workflow versus UV’s streamlined approach. Traditionally, a new project typically means creating a directory, creating a virtual environment with Python 3 venv, activating it, installing packages with pip, and later freezing dependencies into requirements.txt using pip freeze. That process is not only multi-step, it also tends to be error-prone for newcomers because it requires understanding activation, dependency capture, and re-creation on another machine.
With UV, project setup becomes more direct. Instead of manually creating a project folder and virtual environment, UV can initialize a project directory itself (uv init). The default application template generates a ready-to-edit structure including a .gitignore, a Python version file to keep interpreter selection consistent, a starter main.py, and a pyproject.toml for dependency configuration. Crucially, UV defers environment creation: the first time a command needs an environment, UV automatically creates a .venv directory and installs dependencies.
Adding dependencies is done with uv add. Installing Flask and request via uv add flask request updates pyproject.toml automatically and creates a uv.lock file that records exact package versions—including transitive dependencies—so the environment can be reproduced precisely. UV also provides uv tree to visualize dependency relationships, showing which packages depend on which sub-dependencies.
Running code shifts the workflow away from “always-activated” environments. Instead of python main.py, UV uses uv run main.py, which selects the correct environment even when none is active. The tutorial demonstrates resilience: if the .venv directory is deleted, uv run recreates the environment from uv.lock and installs dependencies again before executing the script. For sharing without requiring the recipient to run the app first, uv sync rebuilds the environment to match the lock file. Dependency changes are handled with commands like uv remove flask, which updates both pyproject.toml and uv.lock.
Speed and disk efficiency are presented as major advantages. UV’s global caching system stores shared package versions once across multiple projects, preserving isolation while reducing duplicate downloads and storage. Recreating environments that used to take minutes with pip and venv can become near-instant.
For users hesitant to abandon pip immediately, UV includes a uv pip subcommand that behaves like pip but faster and integrated with project environments. It also supports migrating existing projects by generating UV project structure and installing dependencies from requirements.txt.
Finally, UV extends beyond project dependencies by replacing pipx for Python-based command-line tools. Commands like uv tool install rough install Ruff in an isolated environment while exposing it on the system PATH; uv tool run (and its shortcut uvx) can run tools temporarily without permanent installation. The tutorial closes by emphasizing UV’s “one tool” philosophy: pip, venv, lockfiles, and pipx-style tooling become a cohesive workflow, with additional capabilities for Python version management, package publishing, and optimized Docker builds reserved for later coverage.
Cornell Notes
UV is a unified Python package manager that replaces pip, venv, lockfile generation, and pipx-style tool installation with one workflow. It initializes projects with pyproject.toml and creates a uv.lock file that pins exact dependency versions (including transitive packages) for reproducible environments. UV automatically creates a .venv only when needed, and it can run code without manual activation using uv run. If the virtual environment is deleted, UV recreates it from uv.lock, and uv sync helps teammates rebuild the same environment. UV also supports a uv pip subcommand for gradual migration and includes uv tool / uvx for installing or temporarily running command-line tools like Ruff.
What problem does UV try to solve in the typical Python setup workflow?
How does UV make environments reproducible across machines?
What changes when running a Python script under UV instead of activating a venv?
How does UV handle dependency management after initial setup?
How can users transition from pip without fully switching immediately?
How does UV replace pipx for command-line tools?
Review Questions
- When would you use uv run versus uv sync, and what role does uv.lock play in each?
- What files does UV generate during project initialization, and how do pyproject.toml and uv.lock relate to dependency management?
- How does UV’s uv pip subcommand differ from using UV-native commands like uv add in terms of updating dependency metadata?
Key Points
- 1
UV consolidates pip, venv, lockfile creation, and pipx-style tool installation into one workflow with commands like uv add, uv run, and uv tool install.
- 2
UV generates a uv.lock file that pins exact dependency versions (including transitive dependencies) to make environments reproducible across machines.
- 3
UV creates the .venv automatically when a command needs it, so users don’t have to activate environments manually.
- 4
Running code shifts from python main.py to uv run main.py, and UV can recreate missing environments from uv.lock.
- 5
UV sync rebuilds a project’s environment to match uv.lock, which simplifies onboarding and collaboration.
- 6
UV’s global caching reduces disk usage and speeds up installs by storing shared package versions once across projects.
- 7
UV supports gradual migration via uv pip and can replace pipx with uv tool / uvx for installing or temporarily running tools like Ruff.