tiangolo/fastapi · error · RuntimeError

To use the fastapi command, please install…

Error message

To use the fastapi command, please install "fastapi[standard]":

	pip install "fastapi[standard]"

What it means

RuntimeError raised by fastapi/cli.py:main() when the optional fastapi_cli package cannot be imported (the top-level try/except sets cli_main = None). The function prints the install hint and re-raises so the `fastapi` console script aborts. It exists because FastAPI splits the CLI / dev server out of the core wheel into the fastapi[standard] extra.

Solutions

  1. Install the standard extra: pip install "fastapi[standard]".
  2. Or install the CLI directly: pip install fastapi-cli.
  3. Run the app with uvicorn directly (uvicorn main:app) if you do not want the CLI.
  4. Re-check requirements.txt / pyproject for a bare `fastapi` pin and change it to fastapi[standard].

Example fix

# before
pip install fastapi
fastapi dev app.py
# -> RuntimeError: To use the fastapi command, please install "fastapi[standard]"

# after
pip install "fastapi[standard]"
fastapi dev app.py
Defensive patterns

Strategy: fallback

Validate before calling

# Detect the missing CLI extra before launching the command
import importlib.util, sys
if importlib.util.find_spec("fastapi_cli") is None:
    print("fastapi[standard] not installed; install it or use uvicorn directly")
    sys.exit(1)

Try / catch

try:
    from fastapi_cli.cli import main as cli_main
except ImportError:
    # fallback: run via uvicorn instead of the fastapi CLI
    import uvicorn
    uvicorn.run("main:app", host="127.0.0.1", port=8000)
else:
    cli_main()

Prevention

When it happens

Trigger: Running the `fastapi` command (e.g. `fastapi dev`, `fastapi run`) in an environment where only the slim `fastapi` package is installed and not `fastapi[standard]` or `fastapi-cli`.

Common situations: Installing `pip install fastapi` (slim) instead of `pip install "fastapi[standard]"`; a minimal container/CI image that pins the core wheel; pinning fastapi without its CLI extras; uvicorn installed but the CLI launcher shim still expecting fastapi-cli.

Related errors


AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11). Data as JSON: /api/errors/8ae853f2e1da4213. Report an issue: GitHub.

Appendix: source

Thrown at fastapi/cli.py:12

try:
    from fastapi_cli.cli import main as cli_main

except ImportError:  # pragma: no cover
    cli_main = None  # type: ignore


def main() -> None:
    if not cli_main:  # type: ignore[truthy-function]
        message = 'To use the fastapi command, please install "fastapi[standard]":\n\n\tpip install "fastapi[standard]"\n'
        print(message)
        raise RuntimeError(message)  # noqa: B904
    cli_main()

View on GitHub (pinned to 3e8d1526d8)