UV is a cutting-edge Python packaging and dependency management tool that has been designed to replace pip. UV offers a more efficient, modern approach to managing Python packages, providing enhanced performance and better handling of dependencies. With UV, developers can streamline their workflows, optimize package installations, and ensure cleaner and more reliable environments.
- Why Use
uv? - Prerequisites
- Installing
uv - Core
uvCommands and Use Cases- Virtual Environment Management
- Package Management
- Project Management
- Python Version Management
- Script and Tool Management
- Advanced Features
- Migrating from
pip - Additional Resources
- Speed: UV is optimized for faster package installation and resolution, reducing the time spent on setting up environments and installing dependencies.
- Improved Dependency Resolution: UV uses a more sophisticated algorithm to resolve dependencies, minimizing the chance of version conflicts and ensuring a smoother installation process.
- Built-in Virtual Environment Management: Unlike pip, which requires external tools like
virtualenv, UV offers built-in support for creating and managing virtual environments. - Automatic Compatibility Checks: UV ensures that your Python version is compatible with the installed packages and dependencies, minimizing compatibility issues.
- Streamlined User Interface: UV features a simplified command structure that makes it easier to manage Python environments and packages directly from the command line.
- Speed: 10-100x faster than
pipfor package installation and dependency resolution, thanks to its Rust implementation. - Unified Tool: Replaces multiple tools (
pip,virtualenv,poetry,pipx,pyenv) with a single binary. - Compatibility: Works with existing
requirements.txtfiles and Python packaging standards. - Simplified Workflow: Combines virtual environment creation, package management, and project setup in one tool.
- Cross-Platform: Supports Linux, Windows, and macOS.
- Python: Ensure Python (version 3.7 or higher) is installed on your system, as
uvrequires a Python interpreter to manage dependencies and build packages. - Internet Connection: Required for downloading
uv, Python versions, and packages from PyPI.
- 🚀 A single tool to replace
pip,pip-tools,pipx,poetry,pyenv,twine,virtualenv, and more. - ⚡️ 10-100x faster than
pip. - 🗂️ Provides comprehensive project management, with a universal lockfile.
- ❇️ Runs scripts, with support for inline dependency metadata.
- 🐍 Installs and manages Python versions.
- 🛠️ Runs and installs tools published as Python packages.
- 🔩 Includes a pip-compatible interface for a performance boost with a familiar CLI.
- 🏢 Supports Cargo-style workspaces for scalable projects.
- 💾 Disk-space efficient, with a global cache for dependency deduplication.
- ⏬ Installable without Rust or Python via
curlorpip. - 🖥️ Supports macOS, Linux, and Windows.
If you need to install uv in a Python environment:
pip install uvVerify installation:
uv --versionUse Case: Install uv to start managing Python projects and packages without relying on pip or other tools.
Below are all essential uv commands, grouped by functionality, with their use cases and examples.
uv init <project-name>The uv init command, part of the uv Python package manager, initializes a new Python project by creating a directory with a pyproject.toml file for metadata and dependencies, and optionally a virtual environment.
project-name/
├── pyproject.toml
└── src/
└── project_name/
└── __init__.py
└── __readme.md
uv simplifies creating and managing virtual environments, which are isolated Python environments for project-specific dependencies.
uv venv- Use Case: Creates a virtual environment in the
.venvdirectory in your current project folder. Use this to isolate project dependencies. - Example:
uv venvcreates.venvwith the system's default Python version. - Note: If the required Python version is unavailable,
uvcan download it automatically (see Python Version Management).
uv venv --python 3.11- Use Case: Creates a virtual environment using a specific Python version (e.g., 3.11). Useful when a project requires a particular Python version.
- Example:
uv venv --python 3.11creates.venvwith Python 3.11.
# On Linux/macOS (bash/zsh)
source .venv/bin/activate
# On Windows (Command Prompt)
.venv\Scripts\activate
# On Windows (PowerShell)
.\.venv\Scripts\Activate.ps1- Use Case: Activates the virtual environment, making its Python interpreter and packages available in your shell.
- Example: After activation, running
python --versionshows the virtual environment’s Python version.
uv provides commands to install, remove, and manage packages, replacing pip entirely.
uv add <package>- Use Case: Installs a package into the active virtual environment. Use this to add dependencies like
requestsornumpy. - Example:
uv pip install requestsinstalls therequestslibrary. - Note: Requires an active virtual environment unless using
--system(see Advanced Features).
uv add <package1> <package2>- Use Case: Installs multiple packages at once.
- Example:
uv pip install flask djangoinstalls bothflaskanddjango.
uv add -r requirements.txt- Use Case: Installs all packages listed in a
requirements.txtfile. Ideal for replicating project dependencies. - Example:
uv pip install -r requirements.txtinstalls all dependencies from the file. - Note:
uvis fully compatible withpip-generatedrequirements.txtfiles.
uv remove <package>- Use Case: Removes a package from the virtual environment.
- Example:
uv pip uninstall requestsremoves therequestslibrary.
uv pip sync requirements.txt- Use Case: Ensures the virtual environment matches the exact packages and versions in
requirements.txt, removing any unlisted packages. - Example:
uv pip sync requirements.txtupdates the environment to match the file.
I welcome contributions, suggestions, and feedback!
If you find any issues or want to improve this project, feel free to open a GitHub issue or submit a pull request.
This repo is only for learning and exploring new things, feel free to fork it, explore, or give suggestions!
Star ⭐ the repo if it helps you!