pandas-dev/pandas · critical · ImportError
Unable to import required dependency
Error message
Unable to import required dependency {_dependency}. Please see the traceback for details. What it means
Raised at `import pandas` time when one of the hard dependencies (`numpy` or `python-dateutil`) cannot be imported. pandas runs `__import__` on each name in `_hard_dependencies` during package init and re-raises as a clearer ImportError chained (`raise ... from _e`) to the original failure so the underlying cause stays visible in the traceback.
Solutions
- Install the missing dependency: `python -m pip install numpy python-dateutil` (or just `pip install pandas` which pulls both).
- Verify the import directly: `python -c "import numpy, dateutil"` to see which one fails and why.
- Recreate the virtual environment cleanly and reinstall pandas from scratch to rule out a half-installed state.
- If behind a proxy or offline, ensure numpy and python-dateutil wheels are available in the local index.
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
def pandas_deps_ok() -> bool:
return importlib.util.find_spec('numpy') is not None and importlib.util.find_spec('dateutil') is not None
# call before `import pandas` in tooling/scripts
assert pandas_deps_ok(), 'numpy and python-dateutil must be installed' Type guard
null
Try / catch
try:
import pandas
except ImportError as e:
if 'Unable to import required dependency' in str(e):
# install missing hard dep then retry once
...
raise Prevention
- Pin pandas in requirements so pip resolves numpy/dateutil transitively.
- Create fresh virtualenvs per project; do not mix system and venv packages.
- In CI, assert `importlib.util.find_spec` for numpy and dateutil before running the suite.
- Use `pip check` after installs to detect broken dependency metadata.
When it happens
Trigger: Executing `import pandas` in an environment where `numpy` or `dateutil` is not installed (or is installed but broken/unimportable). The loop at pandas/__init__.py:9-16 catches the bare ImportError and wraps it.
Common situations: Fresh virtualenv created without installing requirements; a partial/broken `pip install pandas` (wheel metadata present but deps missing); wrong interpreter selected in an IDE/CI; a corrupt numpy install from a killed build; conda/pip mix-up where dateutil was uninstalled.
Related errors
- pyarrow>= is required for PyArrow backed…
- pyarrow>= is required for PyArrow backed…
- pyarrow>= is required for PyArrow backed StringArray.
- Cannot apply ufunc to mixed DataFrame and Series inputs.
- Cannot modify read-only array
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/71a228704d5d2fd4.
Report an issue: GitHub.
Appendix: 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 3b7651241d)