Quick-Guide on managing Python like an AI Engineer on macOS with uv
TL;DR Bash Cheat‑sheet
🌙 Why I Migrated to uv
(And You Should Too)
uv
is a lightning-fast, all-in-one Python project tool written in Rust, combining package management, interpreter installation, and virtual environment creation. Key features include:
- Installing and switching between multiple CPython (and PyPy) builds
- Creating lightweight virtual environments
- Resolving dependencies with an absurdly fast pip-compatible resolver
- Modern project management with
pyproject.toml
- A
uvx
shim for running tools like Ruff or Black in isolated sandboxes: uvx black .
oruvx ruff format .
Result: fewer moving parts, faster setups, and consistent environments across laptop and CI images.
1. Installing uv
Note:
uv
auto-detects your architecture (Apple Silicon or Intel).
The same page shows a one‑liner curl installer if you're brew‑averse. Check it worked:
2. Installing Python interpreters
These archives live under ~/.cache/uv
, so they don't fight Homebrew or Xcode.
Need the interpreter for this project only?
Drop that file into Git and your team (or the CI) will automatically get the same binary.
3. Two Workflows: Modern vs Classical
3.1 Modern Workflow: New Projects with pyproject.toml
For new projects or when you want to embrace the modern Python packaging ecosystem:
When cloning an existing uv project:
This creates a complete environment with locked dependencies, ensuring reproducible builds across your team.
3.2 Classical Workflow: Existing Projects with requirements.txt
For existing projects or when working with traditional Python setups:
Pro tip:
uv
automatically detects the.venv
directory, so you rarely need to manually activate environments.
3.3 Using uvx
for Global Tools
With uvx
you can run formatters or linters without touching your virtual environment:
4. Quick Reference Table
Task | Modern (pyproject.toml ) |
Classical (requirements.txt ) |
---|---|---|
Start new project | uv init |
touch requirements.txt |
Add dependency | uv add package |
echo package >> requirements.txt |
Install dependencies | uv sync |
uv pip install -r requirements.txt |
Run script | uv run python script.py |
uv run python script.py |
Run installed tool | uv run tool-name |
uv run tool-name |
Create environment | automatic with uv init | uv venv |
5. Co‑existing with pyenv (if you must)
- Keep pyenv if you rely on its "shim" strategy to globally shadow
python
in your shell. - Skip pyenv if project‑local versions and CI parity are your priority - uv handles that solo.
From uv's perspective every interpreter in $PATH
(even ones compiled by pyenv or Homebrew) is just "system Python". You can pass it to any --python
flag and mix‑and‑match as needed.
6. ML‑specific niceties
- The PyTorch integration guide shows CUDA‑aware installs in one command - excellent for GPU vs. CPU builds on the same Mac.
- Binary wheels pulled by uv are cached, so re‑creating a venv to try a different version of scikit‑learn or TensorFlow feels instant.
- Use
uv add pip
in new projects to ensure Jupyter notebooks work seamlessly in VS Code.