uvの入れ方:uv init、uv add、uv run と pip/venv 比較

uv init / uv add でプロジェクト管理、uv run で activate 省略。

Greenfield Python still means python -m venv, hand-editing requirements.txt, and remembering to activate before every script. uv from Astral (Ruff team) treats a project like a modern package manager: uv init scaffolds pyproject.toml, uv add writes dependencies and a lockfile, and uv run executes scripts in the project environment without a manual activate dance.

Searchers looking for uv インストール uv init uv add スクリプト pip venv want: install the uv CLI, start a project with uv init, add packages with uv add, run entrypoints with uv run, and see how that compares to classic pip + venv. Steps follow docs.astral.sh/uv.

Install uvuv init · uv adduv run · vs pip/venv

向いている人

01

New scripts and small services

uv init plus uv add httpx gets you a lockfile-backed repo in minutes — no separate venv step before the first import.

02

Teams tired of drift between laptops and CI

uv.lock and uv sync make installs reproducible; CI runs the same resolver your machine used.

03

pip/venv users migrating gradually

Keep old repos on uv pip inside .venv if needed — see our uv venv + uv pip guide — but greenfield work fits uv init better.

uv のインストール

  1. 1

    Official installer

    Run the Getting Started command from the docs, e.g. curl -LsSf https://astral.sh/uv/install.sh | sh. Open a new terminal and check uv --version.

  2. 2

    macOS: Homebrew

    brew install uv is documented. Pick one install path so PATH does not hide duplicate binaries.

  3. 3

    Linux / WSL

    Prefer install.sh; verify with which uv and uv --version.

  4. 4

    Optional: managed Python

    uv python install 3.12 downloads an interpreter uv can pin per project — see Python versions on the docs.

uv init でプロジェクト開始

  1. 1

    Create a directory

    mkdir demo-api && cd demo-api, then run uv init. uv writes pyproject.toml, a sample module or app layout, and often a .python-version pin (exact files depend on template flags — check uv init --help).

  2. 2

    Non-interactive

    uv init --name demo-api or documented flags for libraries vs applications; use -h on your installed version before scripting CI.

  3. 3

    First sync

    uv sync creates .venv, installs the project in editable mode when configured, and materializes dependencies from the lockfile when present.

mkdir demo-api && cd demo-api
uv init
uv sync
uv run python -V

uv add で依存追加

  1. 1

    Runtime dependency

    uv add httpx updates pyproject.toml, refreshes uv.lock, and installs into the project environment.

  2. 2

    Dev-only tools

    uv add --dev pytest ruff (flag name per docs) keeps test and lint packages out of production installs when you use dependency groups correctly.

  3. 3

    Remove or upgrade

    uv remove pkg and uv lock --upgrade-package pkg mirror modern package-manager workflows — confirm subcommands with uv add -h.

Compared to pip, you do not manually edit requirements.txt and re-resolve on every machine: the lockfile is the shared source of truth after uv add.

uv run でスクリプト実行

Goalpip + venv habituv project habit
bootstrappython -m venv .venv + activateuv init + uv sync
add librarypip install pkg → freezeuv add pkg
run appactivate + python main.pyuv run python main.py
run toolglobal pipx or venvuv run pytest or uv run --with ruff ruff check .
CI installpip install -r requirements.txtuv sync --frozen
  1. 1

    Project entrypoints

    uv run python main.py or console scripts declared in pyproject.toml — uv selects the project interpreter automatically.

  2. 2

    One-off tools

    uv run --with ruff ruff check . pulls ephemeral tools without polluting global site-packages (see Running scripts on the docs).

  3. 3

    Skip manual activate

    Many teams never source .venv/bin/activate again; if you do activate, behavior should match — verify with which python.

uv init / uv add speed project bootstrap and locked installs; production containers still need explicit Python base-image pins in Dockerfiles — uv does not replace that layer.

Pair on pyproject.toml or CI from the wbroom homepage — create and join a room. For legacy requirements.txt repos, see uv venv and uv pip.

FAQ

Do I still need python -m venv?

Not for new uv projects: uv sync manages .venv. Old repos can keep manual venvs and use uv pip until you adopt pyproject.toml.

Can I import an existing requirements.txt?

uv documents migration paths from requirements files into projects — run the documented import/sync flow on a branch before deleting the old file.

Poetry or pip-tools alongside uv?

Pick one lockfile story per repo. Mixing Poetry’s lock with uv.lock causes drift; document “uv project” in the README when you switch.

CI recipe?

Install uv in the job (install script or official action), uv sync --frozen, then uv run pytest. Never print private index tokens in logs.

会議を始める