ScrapeGraphAI/Scrapegraph-ai · error · ImportError

pandas is not installed. Please install it using `pip instal

Error message

pandas is not installed. Please install it using `pip install pandas`.

What it means

When the fetch input is a CSV file, load_file_content imports pandas; if pandas is not installed in the environment the ImportError is re-raised with install instructions. ScrapeGraphAI does not ship pandas as a hard dependency, so CSV support is opt-in.

Source

Thrown at scrapegraphai/nodes/fetch_node.py:203

            loader = PyPDFLoader(source)
            # PyPDFLoader.load() can be blocking for large PDFs. Run it in a thread and
            # enforce the configured timeout if provided.
            if self.timeout is None:
                return loader.load()
            else:
                with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
                    future = executor.submit(loader.load)
                    try:
                        return future.result(timeout=self.timeout)
                    except concurrent.futures.TimeoutError:
                        raise TimeoutError(
                            f"PDF parsing exceeded timeout of {self.timeout} seconds"
                        )
        elif input_type == "csv":
            try:
                import pandas as pd
            except ImportError:
                raise ImportError(
                    "pandas is not installed. Please install it using `pip install pandas`."
                )
            return [
                Document(
                    page_content=str(pd.read_csv(source)), metadata={"source": "csv"}
                )
            ]
        elif input_type == "json":
            with open(source, encoding="utf-8") as f:
                return [
                    Document(
                        page_content=str(json.load(f)), metadata={"source": "json"}
                    )
                ]
        elif input_type == "xml" or input_type == "md":
            with open(source, "r", encoding="utf-8") as f:
                data = f.read()
            return [Document(page_content=data, metadata={"source": input_type})]

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Install pandas: pip install pandas (or uv add pandas / uv sync --extra with the appropriate extra)
  2. For Dockerfiles, add pandas to the image
  3. Alternatively convert the CSV to another supported format (JSON/text) before fetching

Example fix

# before: raises ImportError on csv source
$ pip install pandas  # shell fix
# after
graph_config = {'source': 'data.csv', ...}  # now works
Defensive patterns

Strategy: validation

Validate before calling

try:
    import pandas  # noqa
    PANDAS_OK = True
except ImportError:
    PANDAS_OK = False

if source.endswith('.csv') and not PANDAS_OK:
    raise SystemExit('pip install pandas before using CSV sources')

Type guard

def csv_supported() -> bool:
    try:
        import pandas  # noqa
        return True
    except ImportError:
        return False

Try / catch

try:
    graph.run()
except ImportError as e:
    if 'pandas' in str(e):
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pandas'])
    else:
        raise

Prevention

When it happens

Trigger: Feeding a .csv source path to a graph (e.g. SmartScraperGraph with source='data.csv') in an environment where pandas is missing — minimal install, slim Docker image, or a venv without extras.

Common situations: Docker/CI images that only install core deps; using csv input for the first time; pandas removed during dependency cleanup.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


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