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.
Same file, two interpreters
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
| Command | Environment | rich import |
|---|---|---|
python example.py | System / leftover venv | Fails — ModuleNotFoundError |
uv run --no-project example.py | Empty on-demand env | Fails — same missing rich |
uv run --with rich example.py | Temporary env with rich | Runs — first success |
uv add --script example.py rich | Writes inline metadata | Then uv run example.py is enough |
uv run in a project | Installs the project too | Use --no-project before the script if you do not want that |
First success, then pin
- 01Install uv
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh. Windows:irm https://astral.sh/uv/install.ps1 | iex. Orbrew install uv. New terminal,uv --version. - 02Write example.py
Import
rich(the docs usefrom rich.progress import track). Do not expect system python to see it. - 03Run with --with
uv run --with rich example.py. That is the first line that should print. Repeat--withfor more packages. Constraints like--with 'rich>12,<13'are allowed. - 04Pin with --script
uv add --script example.py 'requests<3' 'rich'writes a# /// scriptblock. After that,uv run example.py. Optional:uv lock --script example.pyfor 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.pyuv on PATH is not a filled python. First success is
uv run --with, notpython.
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.