uv: first command is run, not python
After uv, typing python still hits the system interpreter.
After installing uv, typing python still hits the interpreter on PATH. The first command in a project is uv run. To sketch the command and interpreter path, start a room.
Official project guide: after uv init, run the entrypoint with uv run. The first uv run, uv sync, or uv lock creates .venv and uv.lock. Bare python never enters that environment.
Put the first command on the right interpreter
- 01Init, then run the entrypoint
Official example:
uv init hello-world, thenuv run hello-worldprints Hello from hello-world!. That is the scripts entry inpyproject.toml, not systempython. - 02Need an interpreter? uv run python
The CLI:
uv runensures the command runs in the project environment with locked dependencies.uv run python -c "import sys; print(sys.executable)"should point at project.venv. On Windows, activation is.venv\Scripts\activate. - 03Without run, you must activate
The guide: the virtual environment must be active to run project commands without
uv run. Flow:uv sync, thensource .venv/bin/activate, thenpython. - 04Put uv flags before the command
uv run file.pyequalsuv run python file.py. uv options must come first, e.g.uv run --python 3.12 -- python. A PEP 723 script installs into an isolated, ephemeral environment.
uv init hello-world
cd hello-world
uv run hello-world
# interpreter inside the project env, not PATH python
uv run python -c "import sys; print(sys.executable)"
# docs.astral.sh/uv/guides/projects/
# docs.astral.sh/uv/reference/cli/#uv-runYou think you are in the project. You are not
| Action | You assume | What happens |
|---|---|---|
Install uv, type python | You are in the project env | Still PATH python; .venv may not exist yet |
python right after uv init | Dependencies are ready | .venv and uv.lock appear on the first uv run / uv sync / uv lock |
uv run python outside a project | A project env is always created | With no venv found, it uses the discovered interpreter |
Default uv run | The env matches the lockfile exactly | No exact sync; extra packages stay unless --exact |
After the first run, still watch these
- Lockfile
- Before every
uv run, uv checksuv.lockagainstpyproject.toml, then the environment against the lock. That is a guarantee, not optional. - Outside a project
- A venv in this or a parent directory is used; otherwise the discovered interpreter. Do not assume a new
.venv. - Scripts
- Inline-metadata scripts use an isolated temporary environment, not the project
.venv.
To put sys.executable and the entrypoint on one sheet, open a frogmeet room: send the id, about one hour, eight people max, no account. Details on features.
FAQ
Why do python and uv run python show different paths?
Bare python follows PATH. Project commands need the project env: uv run, or uv sync then activate .venv.
No .venv after uv init?
The guide: the first project command (uv run, uv sync, or uv lock) creates the virtual environment and lockfile.
Does uv run wipe packages I installed by hand?
Not by default. It makes the minimum changes to satisfy requirements. To drop extras, add --exact. By contrast, uv sync defaults to an exact sync.