huggingface/transformers · error · ImportError
Missing dependencies for serving. Install with `pip install
Error message
Missing dependencies for serving. Install with `pip install transformers[serving]`
What it means
The `transformers serve` command implements an OpenAI-compatible HTTP server using uvicorn and friends, which live behind the optional 'serving' extra. serve() checks is_serve_available() first and raises ImportError with the pip extra hint when the dependencies are missing, before any import of uvicorn happens.
Source
Thrown at src/transformers/cli/serve.py:109
] = None,
cb_max_memory_percent: Annotated[
float | None, typer.Option(help="Max GPU memory fraction for KV cache (0.0-1.0).")
] = None,
cb_use_cuda_graph: Annotated[
bool | None, typer.Option(help="Enable CUDA graphs for continuous batching.")
] = None,
# Server options
host: Annotated[str, typer.Option(help="Server listen address.")] = "localhost",
port: Annotated[int, typer.Option(help="Server listen port.")] = 8000,
enable_cors: Annotated[bool, typer.Option(help="Enable permissive CORS.")] = False,
log_level: Annotated[str, typer.Option(help="Logging level (e.g. 'info', 'warning').")] = "warning",
default_seed: Annotated[int | None, typer.Option(help="Default torch seed.")] = None,
non_blocking: Annotated[
bool, typer.Option(hidden=True, help="Run server in a background thread. Used by tests.")
] = False,
) -> None:
if not is_serve_available():
raise ImportError("Missing dependencies for serving. Install with `pip install transformers[serving]`")
import uvicorn
from .serving.chat_completion import ChatCompletionHandler
from .serving.completion import CompletionHandler
from .serving.model_manager import ModelManager
from .serving.response import ResponseHandler
from .serving.server import build_server
from .serving.transcription import TranscriptionHandler
from .serving.utils import GenerationState
# Seed
if default_seed is not None:
set_torch_seed(default_seed)
# Logging
transformers_logger = logging.get_logger("transformers")
transformers_logger.setLevel(logging.log_levels[log_level.lower()])View on GitHub (pinned to a597f97485)
Solutions
- pip install "transformers[serving]"
- Or add uvicorn/fastapi (plus sse-starlette etc.) manually: pip install uvicorn fastapi
- Rebuild deployment images with the serving extra included
Example fix
# before pip install transformers transformers serve ... # ImportError # after pip install "transformers[serving]" transformers serve ...
Defensive patterns
Strategy: validation
Validate before calling
try:
import uvicorn, fastapi # noqa
except ImportError:
raise SystemExit("pip install 'transformers[serving]' before running serve") Prevention
- Install transformers[serving] by default in deployment images
- Add a dependency check step in container entrypoints
- Keep extras pinned in requirements/lock files
When it happens
Trigger: Running `transformers serve` in an install without the serving extras (plain `pip install transformers`); trimmed Docker images; lock files that stripped optional groups; partial upgrade that removed fastapi/uvicorn.
Common situations: Fresh venvs with base transformers only; CI images minimizing size; users upgrading transformers but not the extras; deploying to slim containers.
Related errors
- You need to install rich to use the chat interface. (`pip in
- You need to install `libcst` to run this command -> `pip ins
- Unknown error
- No server currently running on {url}. To run a local server,
- Unsupported dtype: '{dtype}'. Must be 'auto' or a valid torc
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/15b9bf5d9b18289b.
Report an issue: GitHub.