{"record":{"id":"71a228704d5d2fd4","repo":"pandas-dev/pandas","slug":"unable-to-import-required-dependency-dependency","errorCode":null,"errorMessage":"Unable to import required dependency {_dependency}. Please see the traceback for details.","messagePattern":"Unable to import required dependency (.+?)\\. Please see the traceback for details\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"pandas/__init__.py","lineNumber":13,"sourceCode":"from __future__ import annotations\n\n__docformat__ = \"restructuredtext\"\n\n# Let users know if they're missing any of our hard dependencies\n# except tzdata (see https://github.com/pandas-dev/pandas/issues/63264)\n_hard_dependencies = (\"numpy\", \"dateutil\")\n\nfor _dependency in _hard_dependencies:\n    try:\n        __import__(_dependency)\n    except ImportError as _e:  # pragma: no cover\n        raise ImportError(\n            f\"Unable to import required dependency {_dependency}. \"\n            \"Please see the traceback for details.\"\n        ) from _e\n\ndel _hard_dependencies, _dependency\n\ntry:\n    # numpy compat\n    from pandas.compat import (\n        is_numpy_dev as _is_numpy_dev,  # pyright: ignore[reportUnusedImport] # noqa: F401\n    )\nexcept ImportError as _err:  # pragma: no cover\n    _module = _err.name\n    raise ImportError(\n        f\"C extension: {_module} not built. If you want to import \"\n        \"pandas from the source directory, you may need to run \"\n        \"'python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true' \"\n        \"to build the C extensions first.\"","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/__init__.py#L1-L31","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npython -c \"import pandas\"\n# ImportError: Unable to import required dependency numpy. ...\n\n// after\npython -m pip install numpy python-dateutil\npython -c \"import pandas; print(pandas.__version__)\"","handlingStrategy":"validation","validationCode":"import importlib.util\ndef pandas_deps_ok() -> bool:\n    return importlib.util.find_spec('numpy') is not None and importlib.util.find_spec('dateutil') is not None\n# call before `import pandas` in tooling/scripts\nassert pandas_deps_ok(), 'numpy and python-dateutil must be installed'","typeGuard":"null","tryCatchPattern":"try:\n    import pandas\nexcept ImportError as e:\n    if 'Unable to import required dependency' in str(e):\n        # install missing hard dep then retry once\n        ...\n    raise","preventionTips":["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."],"tags":["dependency","import","environment","numpy","dateutil","install"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}