xtekky/gpt4free · warning · MissingRequirementsError
Install "ddgs" and "beautifulsoup4" | pip install -U g4f[sea
Error message
Install "ddgs" and "beautifulsoup4" | pip install -U g4f[search]
What it means
MissingRequirementsError raised by the DDGS search provider (DDGS.py:212) when the optional search extras are not installed: the module-level has_requirements flag is False because importing 'ddgs' and/or 'beautifulsoup4' failed. g4f keeps web-search support optional, so the provider refuses to run and tells you the exact pip extra to install.
Source
Thrown at g4f/Provider/search/DDGS.py:212
working = has_requirements
@classmethod
async def create_async_generator(
cls,
model: str,
messages: Messages,
prompt: str = None,
proxy: str = None,
timeout: int = 30,
region: str = None,
backend: str = None,
max_results: int = 5,
max_words: int = 2500,
add_text: bool = True,
**kwargs,
) -> AsyncResult:
if not has_requirements:
raise MissingRequirementsError(
'Install "ddgs" and "beautifulsoup4" | pip install -U g4f[search]'
)
prompt = format_media_prompt(messages, prompt)
results: List[SearchResultEntry] = []
# Use the new DDGS() context manager style
with DDGSClient() as ddgs:
for result in ddgs.text(
prompt,
region=region,
safesearch="moderate",
timelimit="y",
max_results=max_results,
backend=backend,
):
if ".google." in result["href"]:
continueView on GitHub (pinned to 973504e177)
Solutions
- Install the search extra: pip install -U g4f[search]
- Or install directly: pip install -U ddgs beautifulsoup4
- Rebuild your Docker image with the extra included
- Verify with: python -c "import ddgs, bs4; print('ok')"
Example fix
# before pip install g4f # after pip install -U "g4f[search]"
Defensive patterns
Strategy: validation
Validate before calling
def search_deps_available() -> bool:
try:
import ddgs # noqa: F401
import bs4 # noqa: F401
return True
except ImportError:
return False
if not search_deps_available():
raise SystemExit("Missing search deps: pip install -U g4f[search]") Type guard
def has_ddgs_requirements() -> bool:
try:
import ddgs, bs4
return True
except ImportError:
return False Try / catch
from g4f.errors import MissingRequirementsError
try:
async for r in DDGS.create_async_generator(model, messages):
...
except MissingRequirementsError:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-U", "g4f[search]"])
raise Prevention
- Install extras at deploy time: pip install -U g4f[search]
- Add an import smoke test for ddgs/bs4 to CI
- Note the package was renamed (duckduckgo_search → ddgs); old pins break
When it happens
Trigger: Invoking DDGS.create_async_generator (directly or via a model request with web search enabled) in an environment where 'import ddgs' or 'import bs4' raises ImportError, flipping has_requirements to False.
Common situations: Base install (pip install g4f) without extras; Docker images built from slim templates; dependency pruned by a resolver conflict; library name changed across g4f versions (duckduckgo_search → ddgs).
Related errors
- Google requires a browser to be installed.
- cloudscraper library is required for Yupp provider | install
- MarkItDown is not installed. Please install it with `pip ins
- Install "gpt4all" package | pip install -U g4f[local]
- ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. Pl
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/904aed5d6bbe9435.
Report an issue: GitHub.