pandas-dev/pandas · critical · ImportError

Unable to import required dependency {_dependency}. Please s

Error message

Unable to import required dependency {_dependency}. Please see the traceback for details.

What it means

Raised at pandas import time when one of its hard dependencies (numpy or dateutil, defined in _hard_dependencies) cannot be imported. pandas re-raises the underlying ImportError chained via 'from _e' so the original traceback is preserved. tzdata is intentionally excluded. This is a fatal startup error: nothing in pandas is usable until it is resolved.

Source

Thrown at pandas/__init__.py:13

from __future__ import annotations

__docformat__ = "restructuredtext"

# Let users know if they're missing any of our hard dependencies
# except tzdata (see https://github.com/pandas-dev/pandas/issues/63264)
_hard_dependencies = ("numpy", "dateutil")

for _dependency in _hard_dependencies:
    try:
        __import__(_dependency)
    except ImportError as _e:  # pragma: no cover
        raise ImportError(
            f"Unable to import required dependency {_dependency}. "
            "Please see the traceback for details."
        ) from _e

del _hard_dependencies, _dependency

try:
    # numpy compat
    from pandas.compat import (
        is_numpy_dev as _is_numpy_dev,  # pyright: ignore[reportUnusedImport] # noqa: F401
    )
except ImportError as _err:  # pragma: no cover
    _module = _err.name
    raise ImportError(
        f"C extension: {_module} not built. If you want to import "
        "pandas from the source directory, you may need to run "
        "'python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true' "
        "to build the C extensions first."

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Run `python -m pip install numpy python-dateutil` (or reinstall pandas with `pip install --force-reinstall pandas`).
  2. Verify the install with `python -c "import numpy; print(numpy.__version__)"` and `python -c "import dateutil"`.
  3. If numpy fails to import, check for ABI mismatch (`numpy.dtype` segfaults or ImportError about C extension) and reinstall numpy matching your Python version.
  4. Check there is no local file named numpy.py or a directory named numpy on sys.path shadowing the real package.

Example fix

# before
python -c "import pandas"  # ImportError: Unable to import required dependency numpy

# after
python -m pip install numpy python-dateutil
python -c "import pandas; print(pandas.__version__)"
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
for dep in ("numpy", "dateutil"):
    if importlib.util.find_spec(dep) is None:
        raise SystemExit(f"Missing hard dependency: {dep}. Run: pip install {dep}")
import pandas  # now safe

Prevention

When it happens

Trigger: import pandas executes the loop at pandas/__init__.py:9-16; if __import__('numpy') or __import__('dateutil') raises ImportError, this message is raised.

Common situations: Fresh venv without numpy/dateutil installed, a broken numpy wheel (e.g. mismatched Python ABI), a corrupted environment after a partial pip upgrade, or sys.path shadowing where a local 'numpy.py' shadows the real package.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/71a228704d5d2fd4. Report an issue: GitHub.