ScrapeGraphAI/Scrapegraph-ai · error · ImportError
The dependencies for screenshot scraping are not installed.
Error message
The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[ocr]`.
What it means
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.
Source
Thrown at scrapegraphai/utils/screenshot_scraping/screenshot_preparation.py:28
from ..logging import get_logger
logger = get_logger(__name__)
async def take_screenshot(url: str, save_path: str = None, quality: int = 100):
"""
Takes a screenshot of a webpage at the specified URL and saves it if the save_path is specified.
Parameters:
url (str): The URL of the webpage to take a screenshot of.
save_path (str): The path to save the screenshot to. Defaults to None.
quality (int): The quality of the jpeg image, between 1 and 100. Defaults to 100.
Returns:
PIL.Image: The screenshot of the webpage as a PIL Image object.
"""
try:
from PIL import Image
except ImportError as e:
raise ImportError(
"The dependencies for screenshot scraping are not installed. "
"Please install them using `pip install scrapegraphai[ocr]`."
) from e
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
image_bytes = await page.screenshot(
path=save_path, type="jpeg", full_page=True, quality=quality
)
await browser.close()
return Image.open(BytesIO(image_bytes))
def select_area_with_opencv(image):
"""
Allows you to manually select an image area using OpenCV.View on GitHub (pinned to 532dfffbf6)
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
Example fix
# before # take_screenshot(url) -> ImportError # after pip install 'scrapegraphai[ocr]'
Defensive patterns
Strategy: validation
Validate before calling
try:
import PIL # noqa
deps_ok = True
except ImportError:
deps_ok = False Try / catch
try:
img = await take_screenshot(url)
except ImportError as e:
raise RuntimeError("install extras: pip install 'scrapegraphai[ocr]'") from e Prevention
- Install the ocr extra in the environment definition (requirements/Dockerfile)
- Check optional imports at app startup
When it happens
Trigger: Calling take_screenshot in an environment where Pillow (or the playwright stack bundled with the ocr extra) is not installed.
Common situations: Base install of scrapegraphai without extras; CI images trimmed of optional deps; Pillow removed accidentally or broken by a version conflict.
Related errors
- module {__name__!r} has no attribute {name!r}
- Could not import the 'ddgs' package required for DuckDuckGo
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/6a4e579624474e42.
Report an issue: GitHub.