{"record":{"id":"6a4e579624474e42","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"the-dependencies-for-screenshot-scraping-are-not-i","errorCode":null,"errorMessage":"The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[ocr]`.","messagePattern":"The dependencies for screenshot scraping are not installed\\. Please install them using `pip install scrapegraphai\\[ocr\\]`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/screenshot_scraping/screenshot_preparation.py","lineNumber":28,"sourceCode":"from ..logging import get_logger\n\nlogger = get_logger(__name__)\n\n\nasync def take_screenshot(url: str, save_path: str = None, quality: int = 100):\n    \"\"\"\n    Takes a screenshot of a webpage at the specified URL and saves it if the save_path is specified.\n    Parameters:\n        url (str): The URL of the webpage to take a screenshot of.\n        save_path (str): The path to save the screenshot to. Defaults to None.\n        quality (int): The quality of the jpeg image, between 1 and 100. Defaults to 100.\n    Returns:\n        PIL.Image: The screenshot of the webpage as a PIL Image object.\n    \"\"\"\n    try:\n        from PIL import Image\n    except ImportError as e:\n        raise ImportError(\n            \"The dependencies for screenshot scraping are not installed. \"\n            \"Please install them using `pip install scrapegraphai[ocr]`.\"\n        ) from e\n\n    async with async_playwright() as p:\n        browser = await p.chromium.launch(headless=True)\n        page = await browser.new_page()\n        await page.goto(url)\n        image_bytes = await page.screenshot(\n            path=save_path, type=\"jpeg\", full_page=True, quality=quality\n        )\n        await browser.close()\n        return Image.open(BytesIO(image_bytes))\n\n\ndef select_area_with_opencv(image):\n    \"\"\"\n    Allows you to manually select an image area using OpenCV.","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/screenshot_scraping/screenshot_preparation.py#L10-L46","documentation":"Raised by take_screenshot when PIL (Pillow) is not importable, meaning the optional screenshot-scraping dependencies are missing. The message points to the 'ocr' extra. The original ImportError is chained.","triggerScenarios":"Calling take_screenshot in an environment where Pillow (or the playwright stack bundled with the ocr extra) is not installed.","commonSituations":"Base install of scrapegraphai without extras; CI images trimmed of optional deps; Pillow removed accidentally or broken by a version conflict.","solutions":["pip install 'scrapegraphai[ocr]' (or uv sync --extra ocr)","Or install Pillow directly: pip install Pillow","Verify playwright browsers are installed (playwright install chromium) if the next step fails","Pin compatible Pillow version if there's a conflict"],"exampleFix":"# before\n# take_screenshot(url) -> ImportError\n# after\npip install 'scrapegraphai[ocr]'","handlingStrategy":"validation","validationCode":"try:\n    import PIL  # noqa\n    deps_ok = True\nexcept ImportError:\n    deps_ok = False","typeGuard":null,"tryCatchPattern":"try:\n    img = await take_screenshot(url)\nexcept ImportError as e:\n    raise RuntimeError(\"install extras: pip install 'scrapegraphai[ocr]'\") from e","preventionTips":["Install the ocr extra in the environment definition (requirements/Dockerfile)","Check optional imports at app startup"],"tags":["dependencies","ocr","screenshot"],"backgroundTag":"missing-dependency","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}