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.

uv inituv rundo not type python

Put the first command on the right interpreter

  1. 01
    Init, then run the entrypoint

    Official example: uv init hello-world, then uv run hello-world prints Hello from hello-world!. That is the scripts entry in pyproject.toml, not system python.

  2. 02
    Need an interpreter? uv run python

    The CLI: uv run ensures 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.

  3. 03
    Without run, you must activate

    The guide: the virtual environment must be active to run project commands without uv run. Flow: uv sync, then source .venv/bin/activate, then python.

  4. 04
    Put uv flags before the command

    uv run file.py equals uv 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-run

You think you are in the project. You are not

ActionYou assumeWhat happens
Install uv, type pythonYou are in the project envStill PATH python; .venv may not exist yet
python right after uv initDependencies are ready.venv and uv.lock appear on the first uv run / uv sync / uv lock
uv run python outside a projectA project env is always createdWith no venv found, it uses the discovered interpreter
Default uv runThe env matches the lockfile exactlyNo exact sync; extra packages stay unless --exact

After the first run, still watch these

Lockfile
Before every uv run, uv checks uv.lock against pyproject.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.

Start a room