ScrapeGraphAI/Scrapegraph-ai · error · ImportError

scrapegraph_py is not installed. Install it with 'pip instal

Error message

scrapegraph_py is not installed. Install it with 'pip install scrapegraph-py'.

What it means

ImportError raised by _detect_api in the scrapegraph-py compatibility layer: it first tries the legacy SDK import (which passes silently), then tries 'from scrapegraph_py import Client'; if that also fails it raises with instructions to install scrapegraph-py. Any of the module's public helpers (extract, scrape, search) trigger the detection.

Source

Thrown at scrapegraphai/integrations/scrapegraph_py_compat.py:27

from typing import Any, Optional, Type

from pydantic import BaseModel


def _detect_api() -> str:
    try:
        from scrapegraph_py import ScrapeGraphAI  # noqa: F401

        return "v3"
    except ImportError:
        pass
    try:
        from scrapegraph_py import Client  # noqa: F401

        return "v2"
    except ImportError as e:
        raise ImportError(
            "scrapegraph_py is not installed. Install it with 'pip install scrapegraph-py'."
        ) from e


def _schema_to_dict(schema: Optional[Type[BaseModel]]) -> Optional[dict]:
    if schema is None:
        return None
    if isinstance(schema, dict):
        return schema
    if isinstance(schema, type) and issubclass(schema, BaseModel):
        return schema.model_json_schema()
    return None


def _unwrap_result(result: Any) -> dict:
    if hasattr(result, "status") and hasattr(result, "data"):
        if result.status != "success":
            raise RuntimeError(

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. pip install scrapegraph-py.
  2. Verify with python -c 'from scrapegraph_py import Client'.
  3. If it still fails after install, check for a dependency conflict (scrapegraph-py renamed or version-pinned elsewhere) and reinstall in the active environment.

Example fix

# before
from scrapegraphai.integrations.scrapegraph_py_compat import extract
result = extract(url, schema=Schema)  # ImportError

# after
# shell: pip install scrapegraph-py
from scrapegraphai.integrations.scrapegraph_py_compat import extract
result = extract(url, schema=Schema)
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec('scrapegraph_py') is None:
    raise SystemExit('Install the SDK: pip install scrapegraph-py')

Type guard

def scrapegraph_py_available() -> bool:
    import importlib.util
    return importlib.util.find_spec('scrapegraph_py') is not None

Try / catch

try:
    from scrapegraphai.integrations.scrapegraph_py_compat import extract
except ImportError as e:
    if 'scrapegraph_py' in str(e):
        raise SystemExit('pip install scrapegraph-py') from e
    raise

Prevention

When it happens

Trigger: Calling scrapegraphai.integrations.scrapegraph_py_compat.extract/scrape/search without the scrapegraph-py package installed; raised from the v2 detection branch via 'from e' chaining.

Common situations: Using the ScrapeGraph Cloud API compat shim with only the base scrapegraphai install; renamed/removed package in a newer SDK (v1 import passes but v2 is gone); broken virtualenv.

Related errors


AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28). Data as JSON: /api/errors/b13005abef1db839. Report an issue: GitHub.