๐Ÿ“ LLM & AI

uv: installation, environments, and reproducible Python project runs

P
Author
PyLand Team
๐Ÿ“…
Published
04.06.2026
โฑ๏ธ
Reading time
2 min
๐Ÿ‘๏ธ
Views
742
๐ŸŒฑ
Level
Beginner

uv manages Python versions, virtual environments, dependencies, and lockfiles.
It is especially useful for learning projects: one command restores the environment,
and uv run executes the application or tests with the correct packages.

Installation

Official installer for macOS and Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows PowerShell:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Homebrew on macOS:

brew install uv

Close and reopen the terminal, then verify the installation:

uv --version

The current installation methods are listed in the
official Astral documentation.

If the uv command is missing

Restart the terminal and retry uv --version. The installer may have updated
PATH, while an already open shell still has the old value.

If it is still missing:

  • macOS/Linux: run command -v uv;
  • Windows PowerShell: run Get-Command uv;
  • check whether the installer printed a PATH warning;
  • do not run the command inside a Python prompt marked with >>>.

Do not copy the uv executable into the project. Fix the installation or PATH.

Opening an existing project

Move into the directory containing pyproject.toml and uv.lock:

cd path/to/project
uv sync --frozen

When the project has a dev group with pytest and learning tools:

uv sync --frozen --dev

The dev group is normally enabled by default, but explicit --dev makes the
intent clear. uv sync creates .venv when it does not exist.

--frozen uses the existing uv.lock without checking or updating it. --locked
instead verifies that the lockfile matches pyproject.toml. Follow the exact command
in the starter repository README.

Running commands

You do not need to activate .venv manually:

uv run python main.py
uv run fastapi dev app/main.py
uv run pytest -q
uv run ruff check .

uv run discovers the project, synchronizes its environment, and runs the command
inside it. Run it from the project directory or one of its children.

Creating a project

uv init my-project
cd my-project
uv add fastapi --extra standard
uv add --dev pytest httpx ruff

Runtime dependencies go to [project].dependencies; development tools use the
standardized dependency group:

[dependency-groups]
dev = [
    "httpx>=0.28",
    "pytest>=8",
    "ruff>=0.12",
]

.venv and uv.lock appear after uv add, uv sync, or the first uv run.

What belongs in Git

Commit:

  • pyproject.toml;
  • uv.lock;
  • .python-version when the project pins Python;
  • source code and tests.

Do not commit:

  • .venv/;
  • .env with secrets;
  • .pytest_cache/, .ruff_cache/, and __pycache__/.

Minimal .gitignore:

.venv/
.env
__pycache__/
.pytest_cache/
.ruff_cache/

Common problems

  • No pyproject.toml found โ€” enter the extracted project directory.
  • The lockfile cannot change with --frozen โ€” keep uv.lock; use uv lock
    without --frozen only for an intentional dependency update.
  • A module is missing after sync โ€” run through uv run and confirm the dependency
    is declared in pyproject.toml.
  • The editor cannot find packages โ€” select <project>/.venv/bin/python, or
    <project>\.venv\Scripts\python.exe on Windows.
  • uv.lock changed unexpectedly โ€” inspect git diff uv.lock; do not commit it
    when the task did not require dependency changes.

Official documentation

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

httpx: A Modern HTTP Client for Python

httpx is a next-generation HTTP client. Its interface is similar to requests, but it supports...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 518
๐Ÿ“

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 541
๐Ÿ“

Typer: CLI Applications Without the Boilerplate

Typer builds CLIs from Python type annotations. No argparse, no manual parsing โ€” just decorators...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 569