Using Python Package Manger uv
uv
is a next-generation Python package manager designed for speed, simplicity, and all-in-one functionality. Built in Rust, it dramatically accelerates dependency resolution and installation. uv
replaces multiple tools by combining virtual environment management, dependency locking, Python version control, and CLI tool installation into a single, unified workflow, all while remaining fully compatible with existing pip
and requirements.txt
workflows.
✅ Key Benefits
- 10–100× faster installs and resolution than pip/Poetry
- Drop-in pip compatibility
- Built-in virtualenv, dependency manager, Python versioning, and CLI tool support
- Simple, unified workflow for modern Python development
⚙️ 1. Install uv
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create virtual environment and activate it
uv venv
source .venv/bin/activate
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Create virtual environment and activate it
uv venv
.venv\Scripts\activate
# Or via pip/pipx
pip install uv
pipx install uv
# Install dependencies
uv add mcp[cli] httpx
# Create our server file
new-item weather.py
🚀 2. Initialize a New Project
uv init myproj
cd myproj
This sets up:
pyproject.toml
.python-version
.gitignore
,README.md
- Optionally a sample
hello.py
A virtual environment (.venv
) is created on demand.
📦 3. Add or Remove Dependencies
uv add requests pandas # Add dependencies
uv remove pandas # Remove a dependency
Dependencies are added to pyproject.toml
and locked automatically.
🔐 4. Lock & Sync
uv lock # Update the lockfile
uv sync # Sync the environment to match locked dependencies
▶️ 5. Run Code in the Environment
uv run python script.py
uv run pytest
You can also run scripts with inline metadata:
uv run example.py
🛠 6. Install CLI Tools
uv tool install ruff
ruff --version
Or run ad-hoc CLI tools:
uvx pycowsay "hello world!"
🐍 7. Manage Python Versions
uv python install 3.10 3.11 3.12
uv python pin 3.12
Each project can have its own pinned Python version.
📋 8. Use Pip-Compatible Commands
uv pip install -r requirements.txt
uv pip compile requirements.in --universal -o requirements.txt
uv pip sync requirements.txt
🧭 CLI Cheatsheet
uv version # Show uv version
uv init <dir> # New project
uv add <pkg> # Add dependency
uv remove <pkg> # Remove dependency
uv lock # Update lockfile
uv sync # Sync environment
uv run <cmd> # Run inside env
uv tool install <tool> # Install CLI tool
uv python install <ver> # Install Python version
uv python pin <ver> # Pin Python version
uv pip compile/sync # Pip-style workflows
uv self update # Update uv itself