UV Python Environment
Core workflow
- Work from the workspace root.
- If no
pyproject.tomlexists, initialize the project withuv init .. - If
pyproject.tomlexists and dependencies are defined, create or repair the env withuv sync --no-cache --upgrade. - Use
uv add <pkg>for runtime dependencies anduv add --dev <pkg>for dev tools (e.g.,ipython,rich,see).
Activate and run
- Activate the venv with
source /path/to/workspace/.venv/bin/activate. - Prefer
uv run python <file.py>to run scripts. - If a Python snippet is needed, write it to a
.pyfile first and then run it. Avoiduv run python -c "<multiline>". - When writing a helper script, avoid
argparseCLI scaffolding. Prefer small, local, low-coupling functions that take arguments, and call them explicitly underif __name__ == "__main__":without amain()function when possible.
Troubleshooting
- If Python is not found, activate the venv or run with
uv run. - If a package is missing, add it with
uv add(oruv add --devfor dev-only tools), then retry.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.