FoundationAgents/MetaGPT · error · ImportError
To use this module, you should have the `google-api-python-c
Error message
To use this module, you should have the `google-api-python-client` Python package installed. You can install it by running the command: `pip install -e.[search-google]`
What it means
Module-level ImportError raised while importing metagpt.tools.search_engine_googleapi: googleapiclient.discovery (provided by google-api-python-client) is not installed. Like the DDG module, it fails on import, so merely referencing the module in config can crash a run.
Source
Thrown at metagpt/tools/search_engine_googleapi.py:18
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations
import asyncio
import json
import warnings
from concurrent import futures
from typing import Optional
from urllib.parse import urlparse
import httplib2
from pydantic import BaseModel, ConfigDict, model_validator
try:
from googleapiclient.discovery import build
except ImportError:
raise ImportError(
"To use this module, you should have the `google-api-python-client` Python package installed. "
"You can install it by running the command: `pip install -e.[search-google]`"
)
class GoogleAPIWrapper(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
api_key: str
cse_id: str
discovery_service_url: Optional[str] = None
loop: Optional[asyncio.AbstractEventLoop] = None
executor: Optional[futures.Executor] = None
proxy: Optional[str] = None
@model_validator(mode="before")
@classmethodView on GitHub (pinned to 11cdf466d0)
Solutions
- Install the extra: pip install -e.[search-google]
- Verify: python -c "from googleapiclient.discovery import build"
- Or use an already-installed engine (e.g. serper/serpapi) instead
Example fix
# before: ImportError on import from metagpt.tools.search_engine_googleapi import GoogleAPIWrapper # after # pip install -e.[search-google] from metagpt.tools.search_engine_googleapi import GoogleAPIWrapper(api_key=..., cse_id=...)
Defensive patterns
Strategy: fallback
Validate before calling
try:
from googleapiclient.discovery import build # noqa: F401
ok = True
except ImportError:
ok = False Try / catch
try:
from metagpt.tools.search_engine_googleapi import GoogleAPIWrapper
except ImportError:
from metagpt.tools.search_engine_ddg import DDGAPIWrapper # fallback engine Prevention
- Install search-google extra before switching config to googleapi
- Lazy-import engine modules and fail with an actionable message
- Smoke-test engine imports in CI for every engine your config can select
When it happens
Trigger: import metagpt.tools.search_engine_googleapi or setting GoogleAPIWrapper as the search provider without the search-google extra installed.
Common situations: Core-only MetaGPT install; switching SearchEngine to 'GoogleAPIWrapper' in config without adding deps; fresh environment built from a slim requirements list.
Related errors
- To use this module, you should have the `duckduckgo_search`
- To use the similarity search, you need to install the RAG mo
- To use google search engine, make sure you provide the `api_
- To use google search engine, make sure you provide the `cse_
- Query cannot be empty or contain only whitespace.
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/368d3eb469d69fcd.
Report an issue: GitHub.