crewAIInc/crewAI · error · ImportError
`serpapi` package not found, please install with `uv add ser
Error message
`serpapi` package not found, please install with `uv add serpapi`
What it means
ImportError raised by the SerpApi base tool when the serpapi package cannot be imported and the interactive click.confirm prompt to install it (`uv add serpapi`) is declined or unavailable. The import is attempted lazily during tool initialization; on decline, the error includes the exact install command. It fires at construction time, before any search is executed.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/serpapi_tool/serpapi_base_tool.py:41
client: Any | None = None
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
try:
from serpapi import Client
except ImportError:
import click
if click.confirm(
"You are missing the 'serpapi' package. Would you like to install it?"
):
import subprocess
subprocess.run(["uv", "add", "serpapi"], check=True) # noqa: S607
from serpapi import Client # type: ignore[import-untyped]
else:
raise ImportError(
"`serpapi` package not found, please install with `uv add serpapi`"
) from None
api_key = os.getenv("SERPAPI_API_KEY")
if not api_key:
raise ValueError(
"Missing API key, you can get the key from https://serpapi.com/manage-api-key"
)
self.client = Client(api_key=api_key)
def _omit_fields(
self, data: dict[str, Any] | list[Any], omit_patterns: list[str]
) -> None:
if isinstance(data, dict):
for field in list(data.keys()):
if any(re.compile(p).match(field) for p in omit_patterns):
data.pop(field, None)
else:
if isinstance(data[field], (dict, list)):View on GitHub (pinned to 754d7323be)
Solutions
- Install it beforehand: `uv add serpapi` (or pip install serpapi).
- Bake the dependency into Docker/CI images so the prompt never appears.
- Set SERPAPI_API_KEY too — the very next check raises if the key is missing.
Example fix
# before (CI, no TTY) tool = SerpApiGoogleSearchTool() # ImportError # after # CI step: uv add serpapi # env: SERPAPI_API_KEY=... tool = SerpApiGoogleSearchTool()
Defensive patterns
Strategy: validation
Validate before calling
def serpapi_available() -> bool:
try:
from serpapi import Client # noqa: F401
return True
except ImportError:
return False
if not serpapi_available():
subprocess.run(["uv", "add", "serpapi"], check=True) Try / catch
try:
tool = SerpApiGoogleSearchTool()
except ImportError as e:
if "serpapi" in str(e):
raise SystemExit("Run `uv add serpapi` before using SerpApi tools") from e
raise Prevention
- Declare serpapi as a project dependency when using SerpApi tools.
- Pre-check imports in CI so optional dependencies never surface as runtime prompts.
- Configure SERPAPI_API_KEY together with the install step.
When it happens
Trigger: Instantiating a SerpApi-based tool (e.g. SerpApiGoogleSearchTool / SerpApiGoogleScholarTool) in an environment where `from serpapi import Client` fails and the install prompt is answered 'no' (or auto-declined in non-interactive CI/Docker).
Common situations: CI pipelines and containers missing the optional dependency; fresh environments where crewai-tools was installed without serpapi; headless runs where click.confirm has no TTY and cannot prompt.
Related errors
- `scrapfly-sdk` package not found, please run `uv add scrapfl
- `selenium` and `webdriver-manager` package not found, please
- The 'tavily-python' package is required. 'click' and 'subpro
- The 'tavily-python' package is required. 'click' and 'subpro
- The 'tavily-python' package is required. 'click' and 'subpro
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/cc768b14bb39b469.
Report an issue: GitHub.