{"record":{"id":"904aed5d6bbe9435","repo":"xtekky/gpt4free","slug":"install-ddgs-and-beautifulsoup4-pip-install","errorCode":null,"errorMessage":"Install \"ddgs\" and \"beautifulsoup4\" | pip install -U g4f[search]","messagePattern":"Install \"ddgs\" and \"beautifulsoup4\" \\| pip install -U g4f\\[search\\]","errorType":"exception","errorClass":"MissingRequirementsError","httpStatus":null,"severity":"warning","filePath":"g4f/Provider/search/DDGS.py","lineNumber":212,"sourceCode":"    working = has_requirements\n\n    @classmethod\n    async def create_async_generator(\n        cls,\n        model: str,\n        messages: Messages,\n        prompt: str = None,\n        proxy: str = None,\n        timeout: int = 30,\n        region: str = None,\n        backend: str = None,\n        max_results: int = 5,\n        max_words: int = 2500,\n        add_text: bool = True,\n        **kwargs,\n    ) -> AsyncResult:\n        if not has_requirements:\n            raise MissingRequirementsError(\n                'Install \"ddgs\" and \"beautifulsoup4\" | pip install -U g4f[search]'\n            )\n\n        prompt = format_media_prompt(messages, prompt)\n        results: List[SearchResultEntry] = []\n\n        # Use the new DDGS() context manager style\n        with DDGSClient() as ddgs:\n            for result in ddgs.text(\n                prompt,\n                region=region,\n                safesearch=\"moderate\",\n                timelimit=\"y\",\n                max_results=max_results,\n                backend=backend,\n            ):\n                if \".google.\" in result[\"href\"]:\n                    continue","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/search/DDGS.py#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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')\""],"exampleFix":"# before\npip install g4f\n\n# after\npip install -U \"g4f[search]\"","handlingStrategy":"validation","validationCode":"def search_deps_available() -> bool:\n    try:\n        import ddgs  # noqa: F401\n        import bs4  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif not search_deps_available():\n    raise SystemExit(\"Missing search deps: pip install -U g4f[search]\")","typeGuard":"def has_ddgs_requirements() -> bool:\n    try:\n        import ddgs, bs4\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"from g4f.errors import MissingRequirementsError\ntry:\n    async for r in DDGS.create_async_generator(model, messages):\n        ...\nexcept MissingRequirementsError:\n    subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"-U\", \"g4f[search]\"])\n    raise","preventionTips":["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"],"tags":["search","dependencies","ddgs","setup"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}