python still ModuleNotFound after uv

After uv is installed, python example.py still misses the module. First success is uv run --with, not python.

You installed uv, then typed python example.py. If the file imports rich, you still get ModuleNotFoundError. To put both paths on one page, open sitdraw.

The stall is not the installer. It is treating uv on PATH as a new python. System python still has no rich.

Install uvuv run --with richOptional uv add --script

Same file, two interpreters

pythonSystem env, no rich
--withOn-demand env
PEP 723After uv add --script

python example.py

Uses whatever python is on PATH. Packages uv would fetch are not there. Official docs show ModuleNotFoundError: No module named 'rich' when you skip the env.

uv run example.py

Creates the env for you. First success with a third-party import is uv run --with rich example.py. See also the uv install note.

Which command actually imports

CommandEnvironmentrich import
python example.pySystem / leftover venvFails — ModuleNotFoundError
uv run --no-project example.pyEmpty on-demand envFails — same missing rich
uv run --with rich example.pyTemporary env with richRuns — first success
uv add --script example.py richWrites inline metadataThen uv run example.py is enough
uv run in a projectInstalls the project tooUse --no-project before the script if you do not want that

First success, then pin

  1. 01
    Install uv

    macOS/Linux: curl -LsSf https://astral.sh/uv/install.sh | sh. Windows: irm https://astral.sh/uv/install.ps1 | iex. Or brew install uv. New terminal, uv --version.

  2. 02
    Write example.py

    Import rich (the docs use from rich.progress import track). Do not expect system python to see it.

  3. 03
    Run with --with

    uv run --with rich example.py. That is the first line that should print. Repeat --with for more packages. Constraints like --with 'rich>12,<13' are allowed.

  4. 04
    Pin with --script

    uv add --script example.py 'requests<3' 'rich' writes a # /// script block. After that, uv run example.py. Optional: uv lock --script example.py for a sidecar lockfile.

# example.py needs rich — python will miss it
from rich.progress import track
import time
for i in track(range(20), description="For example:"):
    time.sleep(0.05)

python example.py
# ModuleNotFoundError: No module named 'rich'

uv run --with rich example.py
uv add --script example.py 'requests<3' 'rich'
uv run example.py

uv on PATH is not a filled python. First success is uv run --with, not python.

To keep the two command paths on one canvas, read the guide, then open a space from the start of the page.

Why does python still fail after uv install?

uv is a runner and installer. It does not inject packages into the python that happens to be first on PATH. Use uv run.

Do I need --no-project?

Only in a directory with pyproject.toml if the script should not install that project. Put the flag before the script name. With inline metadata, project deps are already ignored.

When do I use uv add --script?

After --with works once. It writes dependencies into the file so the next uv run example.py does not need --with.

Stop typing python first

If python example.py still raises ModuleNotFoundError, that is expected. Switch the first command to uv run.

Start the picture