{"record":{"id":"20463dd63301e898","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"could-not-import-the-ddgs-package-required-for-d","errorCode":null,"errorMessage":"Could not import the 'ddgs' package required for DuckDuckGo search. Please install it with `pip install -U ddgs`.","messagePattern":"Could not import the 'ddgs' package required for DuckDuckGo search\\. Please install it with `pip install -U ddgs`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/research_web.py","lineNumber":268,"sourceCode":"    Helper function for DuckDuckGo search using the ``ddgs`` package.\n\n    The ``duckduckgo-search`` package was renamed to ``ddgs``; recent\n    ``langchain-community`` releases import ``from ddgs import DDGS``, which\n    silently broke the previous langchain-based implementation. This calls\n    ``ddgs`` directly so results no longer depend on parsing a formatted string.\n\n    Args:\n        query (str): Search query\n        max_results (int): Maximum number of results to return\n        proxy (str, optional): Proxy configuration\n\n    Returns:\n        List[str]: List of URLs from search results\n    \"\"\"\n    try:\n        from ddgs import DDGS\n    except ImportError as e:\n        raise ImportError(\n            \"Could not import the 'ddgs' package required for DuckDuckGo \"\n            \"search. Please install it with `pip install -U ddgs`.\"\n        ) from e\n\n    try:\n        with DDGS(proxy=proxy) as ddgs:\n            results = [\n                result[\"href\"]\n                for result in ddgs.text(query, max_results=max_results)\n                if result.get(\"href\")\n            ]\n        return results\n    except Exception as e:\n        raise SearchRequestError(f\"DuckDuckGo search failed: {str(e)}\")\n\n\ndef _search_bing(\n    query: str, max_results: int, timeout: int, proxy: Optional[str] = None","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/research_web.py#L250-L286","documentation":"Raised by the DuckDuckGo backend when the optional 'ddgs' package is not installed. The error message tells the user to install it via pip. It is chained from the original ImportError.","triggerScenarios":"Calling search_on_web with search_engine='duckduckgo' (or having it as default/fallback) without the ddgs package installed in the environment.","commonSituations":"Installing scrapegraphai without the [search] or duckduckgo extras; using a minimal Docker image; a fresh virtualenv where only core deps were installed.","solutions":["pip install -U ddgs (or uv add ddgs)","Or install scrapegraphai with the appropriate extras","Or switch to an engine whose deps are already available (e.g. google scraping needs no extra package)"],"exampleFix":"// before\n# engine='duckduckgo' -> ImportError\n// after\npip install -U ddgs","handlingStrategy":"validation","validationCode":"try:\n    import ddgs  # noqa\n    has_ddgs = True\nexcept ImportError:\n    has_ddgs = False\nif config.search_engine == \"duckduckgo\" and not has_ddgs:\n    config.search_engine = \"google\"","typeGuard":null,"tryCatchPattern":"try:\n    results = search_on_web(config)\nexcept ImportError as e:\n    print(e); import subprocess; subprocess.run([\"pip\", \"install\", \"-U\", \"ddgs\"])","preventionTips":["Install extras at environment setup time (pip install scrapegraphai[ocr]/search extras)","Probe for optional packages before selecting that engine"],"tags":["dependencies","import","duckduckgo"],"backgroundTag":"missing-dependency","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}