Как установить uv: uv init, uv add, uv run и сравнение с pip/venv
Проекты через uv init/uv add; uv run вместо ручного activate venv.
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.
Кому подойдёт workflow проекта
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.
Teams tired of drift between laptops and CI
uv.lock and uv sync make installs reproducible; CI runs the same resolver your machine used.
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 (macOS / Linux)
- 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 checkuv --version. - 2
macOS: Homebrew
brew install uvis documented. Pick one install path so PATH does not hide duplicate binaries. - 3
Linux / WSL
Prefer
install.sh; verify withwhich uvanduv --version. - 4
Optional: managed Python
uv python install 3.12downloads an interpreter uv can pin per project — see Python versions on the docs.
Старт проекта через uv init
- 1
Create a directory
mkdir demo-api && cd demo-api, then runuv init. uv writespyproject.toml, a sample module or app layout, and often a.python-versionpin (exact files depend on template flags — checkuv init --help). - 2
Non-interactive
uv init --name demo-apior documented flags for libraries vs applications; use-hon your installed version before scripting CI. - 3
First sync
uv synccreates.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
Runtime dependency
uv add httpxupdatespyproject.toml, refreshesuv.lock, and installs into the project environment. - 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
Remove or upgrade
uv remove pkganduv lock --upgrade-package pkgmirror modern package-manager workflows — confirm subcommands withuv 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
| Goal | pip + venv habit | uv project habit |
|---|---|---|
| bootstrap | python -m venv .venv + activate | uv init + uv sync |
| add library | pip install pkg → freeze | uv add pkg |
| run app | activate + python main.py | uv run python main.py |
| run tool | global pipx or venv | uv run pytest or uv run --with ruff ruff check . |
| CI install | pip install -r requirements.txt | uv sync --frozen |
- 1
Project entrypoints
uv run python main.pyor console scripts declared inpyproject.toml— uv selects the project interpreter automatically. - 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
Skip manual activate
Many teams never
source .venv/bin/activateagain; if you do activate, behavior should match — verify withwhich python.
uv init/uv addspeed 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.
Вопросы для проверки
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.