uv for Python: install, uv venv, uv pip, projects and uvx
What Astral's uv is, how to install it, uv python install, uv venv vs python -m venv, uv pip, uv.lock projects, and uvx for MCP servers in coding agents.
uv is Astral’s Python package and project manager, one Rust binary that does the jobs of pip, venv, pipx and pyenv. Install it with curl -LsSf https://astral.sh/uv/install.sh | sh (or brew install uv, or pipx install uv); it puts uv and uvx in ~/.local/bin. Then uv python install fetches a Python, uv venv makes a .venv, uv pip install fills it, and uv init, uv add and uv run manage a project with a uv.lock. uvx runs a Python command-line tool without installing it, which is how many MCP servers are started from Claude Code, Codex and OpenCode. The current release is 0.13.13 (December 4, 2026).
What uv replaces
Astral describes uv as “an extremely fast Python package and project manager, written in Rust”, meant to replace pip, pip-tools, pipx, poetry, pyenv, twine and virtualenv, and claims it is 10 to 100 times faster than pip. In practice that means one tool for four jobs that used to need four:
| Job | Before | With uv |
|---|---|---|
Get a Python version | pyenv, or the OS package | uv python install 3.12 |
Make a virtual environment | python -m venv .venv | uv venv |
Install packages into it | pip install | uv pip install, or uv add in a project |
Run a command-line tool in isolation | pipx | uvx or uv tool install |
It runs on Linux, macOS and Windows, and needs no Python of its own to start: it is a standalone binary that downloads Python when a command needs one.
Installing uv
The standalone installer is a shell script. It downloads the uv release for your platform from Astral’s release server (falling back to GitHub), checks it against a SHA-256 written into the script, and copies uv and uvx into ~/.local/bin (or $XDG_BIN_HOME if you set one). It needs no root. It then adds one line, . "$HOME/.local/bin/env", to your shell startup files: whichever of .profile, .bashrc, .bash_profile and .bash_login exist, .zshrc or .zshenv for zsh, and a file in fish’s conf.d. That line puts ~/.local/bin on your PATH. On Linux or macOS:
curl -LsSf https://astral.sh/uv/install.sh | shCopiedTo read the script before it runs, save it, look, then run the file:
curl -LsSf https://astral.sh/uv/install.sh -o uv-install.sh
less uv-install.sh
sh uv-install.shCopiedA version in the URL installs that release, which is what you want on a server you will rebuild: https://astral.sh/uv/0.13.13/install.sh. Setting UV_NO_MODIFY_PATH=1 for the run leaves your startup files alone, and UV_INSTALL_DIR picks another directory for the binaries. On Windows the installation page gives the PowerShell equivalent, which pipes install.ps1 into iex under a bypassed execution policy.
The same page lists package-manager routes:
brew install uv
pipx install uvCopiedpip install uv also works, though Astral recommends pipx for the isolation, and Debian and Ubuntu refuse a system-wide pip install anyway (below). WinGet, Scoop, MacPorts, Cargo and a Docker image at ghcr.io/astral-sh/uv are there too. A uv from the standalone installer updates itself with uv self update; one from Homebrew, pipx or pip has self-update switched off and is updated by the tool that installed it.
Open a new shell, or source the file the installer printed, and check:
uv --versionCopiedPython versions: uv python install
uv downloads Python builds from Astral’s python-build-standalone project into ~/.local/share/uv/python, separate from the system’s Python, so installing one never touches what apt manages:
uv python install
uv python install 3.12
uv python install 3.11 3.12
uv python listCopiedWith no version, it installs the latest stable; since uv 0.13.0 (October 9, 2026) that is Python 3.15. Each install also puts a versioned command such as python3.12 in ~/.local/bin. Plain python and python3 are left alone unless you add the --default flag, which the docs call experimental. uv python upgrade moves every uv-managed version to its latest patch release.
You rarely need to run this by hand. uv uses a system Python when one satisfies the command, and downloads a managed one when none does, so a tool that needs 3.11 on an Ubuntu 22.04 server (Python 3.10) just works. In a project, uv python pin 3.12 writes a .python-version file that every uv command in that directory honours. To forbid downloads, pass --no-python-downloads.
uv venv versus python -m venv
Both make a standard virtual environment that activates the same way:
uv venv
source .venv/bin/activateCopiedThe differences are in what they assume about the machine:
python -m venv .venv | uv venv | |
|---|---|---|
Default location | The path you give | .venv in the current directory |
Python version | The interpreter you ran it with | --python 3.12, downloaded if missing |
pip inside | Yes, unless --without-pip | No, unless --seed |
On Debian and Ubuntu | Needs the python3-venv package | Needs nothing extra |
Run again over an existing one | Reuses it; --clear empties it first | Asks before replacing it, or fails with no terminal |
The last row matters when an agent or a script runs the command. In a terminal, a second uv venv asks whether to replace the existing .venv; with no terminal to ask on, it stops with an error instead. Adding --clear (or setting UV_VENV_CLEAR=1) deletes the old environment and everything installed in it without asking, and --allow-existing writes over it while keeping other files in the directory.
The Debian row is the error many people meet first on a fresh Ubuntu server, where the system Python ships with its pip bootstrap disabled:
The virtual environment was not created successfully because ensurepip is not available.
On Debian/Ubuntu systems, you need to install the python3-venv package using the following command.Copiedsudo apt install python3-venv fixes it; the message sometimes names a versioned package such as python3.11-venv that does not exist on that release, and an Ubuntu 24.04 bug report found the generic package was the one needed. uv venv avoids it because it installs no pip and so never calls ensurepip. The flip side: inside a uv-made environment, install with uv pip install, or create it with --seed if some script insists on calling pip.
uv pip install and “externally-managed-environment”
On Debian 12 and later, and on Ubuntu since 23.04, a plain pip install outside a virtual environment stops with:
error: externally-managed-environment
× This environment is externally managedCopiedfollowed by the distribution’s advice. This is PEP 668: the distribution puts an EXTERNALLY-MANAGED file next to the system Python’s standard library, and installers refuse to write there because apt owns those packages. pip’s own note offers --break-system-packages “at the risk of breaking your Python installation or OS”. On a server that is a bad trade; the Debian 12 release notes point to pipx for applications and a virtual environment for libraries, and uv does both.
uv sidesteps the error by never aiming at the system Python unless told to. “Unlike pip, uv requires using a virtual environment by default”: it looks for an active one through VIRTUAL_ENV, then for .venv in the current directory or the nearest parent, and installs there:
uv venv
uv pip install requests
uv pip install -r requirements.txtCopiedNo activation is needed for that; activate only to run python yourself. The --system flag targets the first Python on your PATH the way pip does, and on a marked distribution Python uv honours the same marker: its --break-system-packages flag exists to “allow uv to modify an EXTERNALLY-MANAGED Python installation”. For a command-line program you want available everywhere, the answer is not either flag but uv tool install (below).
Projects: uv init, uv add, uv sync, uv run
For your own code, uv manages the whole project from pyproject.toml:
uv init myapp
cd myapp
uv add requests
uv add --dev pytest
uv run python -c "import requests; print(requests.__version__)"CopiedAs of December 2026 a default uv init makes a packaged application: a .python-version, a README.md, a pyproject.toml with a uv_build build backend and a script entry, and the code under src/myapp/__init__.py. uv init --no-package gives the flatter layout with a main.py, --lib a library, and --bare only the pyproject.toml.
uv addwrites the dependency intopyproject.tomland updates the lockfile and the environment in one step;uv add "httpx>=0.20"takes a constraint,uv add -r requirements.txtimports an old file, anduv removeundoes it.uv.lockrecords the exact version of every package for every platform. Astral says it “should be checked into version control”; the.venvshould not, as Python’s own docs say of any virtual environment.uv runchecks that the lockfile matchespyproject.tomland the environment matches the lockfile before every command, then runs it, so you never activate anything.uv syncbrings.venvin line with the lockfile without running anything, which is the step for a fresh clone or a CI job.uv lock --upgrade-package requestsmoves one package and leaves the rest pinned.
This is the shape to tell a coding agent to use in a Python repo: uv run pytest and uv add leave no doubt about which interpreter and which environment a command ran in, where a bare pip install followed by python can land in two different places.
Tools: uv tool install and uvx
uvx is short for uv tool run. It resolves a package from PyPI, builds an isolated environment for it in uv’s cache, and runs its command:
uvx ruff check .
uvx --from httpie http https://example.com
uvx --with mkdocs-material mkdocs --helpCopied--from names the package when it differs from the command, and --with adds packages to the tool’s environment. For a tool you use daily, uv tool install ruff makes a permanent environment in ~/.local/share/uv/tools and links the command into ~/.local/bin; uv warns if that directory is not on your PATH, and uv tool update-shell adds it. uv tool list, uv tool upgrade --all and uv tool uninstall ruff do what they say. This is the pipx replacement, and the right home for a Python CLI on a Debian-family server.
Which version uvx runs is worth knowing. The tools concept page says the first run takes the latest release and later runs reuse the cached one “unless a different version is requested”, though the sentence after it says a later run uses the latest; the page does not settle it. If the tool is also installed with uv tool install, uvx uses that installed version. uvx ruff@latest asks for the newest and refreshes the cache. An exact version removes the question:
uvx ruff@0.14.0 check .
uvx --from 'ruff>=0.13,<0.15' ruff check .CopiedThe @ form takes exact versions only; ranges go through --from.
uvx as the launcher for MCP servers
MCP servers written in Python often tell you to start them with uvx rather than install them; the reference fetch server’s README says that “no specific installation is needed” with uv. The coding agent starts the command as a child process when a session opens, and uvx fetches the package (and a Python new enough for it) on the first start. Here is the fetch server, which needs Python 3.11.5 or later, pinned to its release of November 27, 2026, in each agent’s documented form.
Claude Code, from the command line (everything after -- is the server’s command):
claude mcp add --transport stdio fetch -- uvx mcp-server-fetch@2026.11.27Copiedor in a project’s .mcp.json, where an entry with no type is read as a local server:
{
"mcpServers": {
"fetch": {
"command": "uvx",
"args": ["mcp-server-fetch@2026.11.27"]
}
}
}CopiedCodex, with codex mcp add or in ~/.codex/config.toml:
codex mcp add fetch -- uvx mcp-server-fetch@2026.11.27Copied[mcp_servers.fetch]
command = "uvx"
args = ["mcp-server-fetch@2026.11.27"]CopiedOpenCode 2, where servers sit under mcp.servers and the command is one array, in opencode.json or with opencode mcp add fetch -- uvx mcp-server-fetch@2026.11.27:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"fetch": {
"type": "local",
"command": ["uvx", "mcp-server-fetch@2026.11.27"]
}
}
}
}CopiedScopes, keys and the rest of each agent’s options are in the guides to Claude Code’s MCP servers, Codex’s and OpenCode’s. One detail of this particular server matters on a cloud machine: by default it refuses private, loopback and link-local addresses, cloud metadata endpoints included, and checks every redirect the same way. The exception is a request sent through a proxy, where the proxy makes the connection. --allow-private-ips removes the guard, so leave it off.
Pin the version
A bare uvx some-server in an agent’s config runs whatever version that machine’s uv settles on, which the docs describe both ways above. Either way, two machines set up a week apart can run different code from the same config, and a new release of the package can reach your agent without anyone reading it. An MCP server runs as your user with your files and whatever keys you pass it. Writing package@version makes the config say exactly what runs, the same on every machine, and an upgrade becomes an edit you make on purpose. Check the package’s page on PyPI for the current version before you pin it.
When the agent cannot find uvx
The agent looks up uvx on its own PATH, which is the one it inherited when it started. The installer put ~/.local/bin on the PATH by editing shell startup files, so an agent started by something that never reads those files (a systemd service, cron), or from a shell opened before uv was installed, gets a PATH without it, and the server fails to start while uvx works fine in your terminal. Claude Code passes a local server the environment it was started with, unless CLAUDE_CODE_MCP_ALLOWLIST_ENV=1 is set, which gives the server only a baseline environment plus its configured env. Codex starts local servers with a cleared environment that keeps its own PATH and HOME, as the Codex MCP guide details.
The durable fix is the full path. Find it:
command -v uvxCopiedand put what it prints, such as /home/you/.local/bin/uvx, in the config’s command in place of uvx. Restarting the agent from a fresh login shell also works, until the next time it is started some other way. For an agent run as a systemd user service, the full path in the config is the only reliable choice. If you manage tools with mise, the same reasoning applies to its shims; the mise guide covers that side.
A first start can also be slow, since uvx may download the package and a Python before the server answers. Codex waits 10 seconds by default (startup_timeout_sec). Reading the two together, running the exact command once in a shell before the agent needs it fills uv’s cache so the agent’s start is fast; raising the timeout is the other way. The server needs no input, so stop it with Ctrl+C once it is running.
The cache: where it is and how to clean it
uv keeps downloaded wheels, built packages and every uvx environment in one cache, at ~/.cache/uv on Linux and macOS ($XDG_CACHE_HOME/uv if that is set) and %LOCALAPPDATA%\uv\cache on Windows. UV_CACHE_DIR moves it. To see where and how big:
uv cache dir
uv cache sizeCopiedOn a small server disk it grows with every package version you try. The routine way to shrink it removes unused entries, along with any project environments uv keeps centrally rather than in a project’s own .venv:
uv cache pruneCopiedThe next command deletes the entire cache; uv cache clean ruff drops one package instead:
uv cache cleanCopiedCleaning removes the uvx environments too; uv rebuilds them on the next run, which means downloads, and the slow first start above, for every MCP server launched that way. Tools from uv tool install and Pythons from uv python install live outside the cache and are not touched. Use these commands rather than rm: Astral says it is “never safe to modify the cache directly”, and the commands wait (up to five minutes by default) for other uv processes, such as an agent’s running server, to let go.
Keep the cache on the same file system as your projects. uv links files from the cache into each environment; across file systems it cannot, and falls back to slower copying.
Updating and removing uv
uv releases often: 0.13.12 came out on December 1, 2026 and 0.13.13 on December 4, both listed on its GitHub releases. uv self update updates a standalone install; brew upgrade uv or pipx upgrade uv the others.
Removing a standalone install takes the two binaries; Astral lists clearing uv’s data first as optional. The first three lines below delete the cache, every uv-managed Python and every tool installed with uv tool install, so leave them out if you want any of that kept. They need uv still present, so they come before the last line:
uv cache clean
rm -r "$(uv python dir)"
rm -r "$(uv tool dir)"
rm ~/.local/bin/uv ~/.local/bin/uvxCopiedInstalls older than 0.5.0 put the binaries in ~/.cargo/bin instead. The line the installer added to your startup files stays until you delete it.