Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Working with uv

uv is a fast Python package and project manager written in Rust. It replaces pip, venv, pip-tools, and pyenv with a single tool. This project uses uv for all dependency management.

Installing uv

macOS / Linux
Windows (PowerShell)
Homebrew
curl -LsSf https://astral.sh/uv/install.sh | sh

After installation, restart your terminal and verify:

uv --version

Key Concepts

uv sync — install everything

uv sync

This single command:

  1. Creates a virtual environment (.venv/) if one doesn’t exist

  2. Installs all dependencies listed in pyproject.toml

  3. Installs the project itself in editable mode (like pip install -e .)

  4. Locks versions in uv.lock so everyone gets identical packages

You only need to run this once after cloning. Run it again if dependencies change (i.e. someone updates pyproject.toml).

uv run — run commands in the project environment

uv run qebench stats
uv run qebench translate -n 5
uv run pytest tests/ -v

uv run automatically activates the virtual environment for the command. You never need to manually source .venv/bin/activate. This is the recommended way to run all project commands.

uv add — add a new dependency

uv add requests            # add a runtime dependency
uv add --dev ruff          # add a dev-only dependency

This updates pyproject.toml and uv.lock in one step. You don’t edit pyproject.toml by hand for dependencies.

Common Workflows

First-time setup

git clone https://github.com/QuantEcon/benchmark.translate-zh-cn.git
cd benchmark.translate-zh-cn
uv sync
uv run qebench doctor

Daily use

uv run qebench translate       # practice translations
uv run qebench add             # add new entries
uv run qebench submit          # push your work

Running tests (developers)

uv sync --extra dev             # install dev dependencies (pytest, ruff)
uv run pytest tests/ -v         # run all tests
uv run ruff check src/ tests/   # lint
uv run ruff format src/ tests/  # auto-format

Updating after a git pull

If someone changed the dependencies:

git pull
uv sync

That’s it — uv resolves and installs any new or changed packages.

How uv Differs from pip

Taskpip + venvuv
Create environmentpython -m venv .venvuv sync (automatic)
Activate environmentsource .venv/bin/activateNot needed (uv run)
Install dependenciespip install -r requirements.txtuv sync
Install projectpip install -e .uv sync (included)
Add a packageEdit requirements.txt + pip installuv add package
Lock versionspip freeze > requirements.txtuv.lock (automatic)
Run a commandMust activate venv firstuv run command

The key insight: uv sync does what 3-4 pip commands do, and uv run removes the need to think about virtual environment activation.

File Reference

FilePurpose
pyproject.tomlProject metadata + dependency declarations
uv.lockExact locked versions (committed to git)
.venv/Virtual environment directory (git-ignored)
.python-versionPython version for the project (if present)

Troubleshooting

“uv: command not found” — Restart your terminal after installing, or add ~/.cargo/bin (or ~/.local/bin) to your PATH.

“No Python found” — uv can install Python for you:

uv python install 3.12

“Packages out of date after git pull” — Just run uv sync again.

Want to start fresh? — Delete .venv/ and re-run uv sync:

rm -rf .venv
uv sync

Further Reading