pandas-dev/pandas · critical · ImportError

C extension: {_module} not built. If you want to import pand

Error message

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.

What it means

Raised when `from pandas.compat import ...` fails with an ImportError at pandas/__init__.py:20-25, which typically means a compiled C extension (e.g. pandas._libs) is missing. This happens when running pandas from a source checkout without having built the Cython/C extensions. The chained ImportError's .name attribute is used for the module name.

Source

Thrown at pandas/__init__.py:27

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."
    ) from _err

from pandas._config import (
    get_option,
    set_option,
    reset_option,
    describe_option,
    option_context,
    options,
)

# let init-time option registration happen
import pandas.core.config_init  # pyright: ignore[reportUnusedImport] # noqa: F401

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Build the extensions in place: `python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true` (the exact command in the message).
  2. Ensure build deps are present first: `python -m pip install meson-python meson ninja Cython>=3.0.0 versioneer`.
  3. Alternatively install a released wheel: `python -m pip install pandas` (no build needed).
  4. Run `python setup.py build_ext --inplace` only on legacy branches; modern main uses Meson via the editable install command above.

Example fix

# before
$ python -c "import pandas"  # C extension: pandas._libs not built

# after
$ python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true
$ python -c "import pandas; print(pandas.__version__)"
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec("pandas._libs") is None:
    raise SystemExit("pandas C extensions not built; run: python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true")

Prevention

When it happens

Trigger: Importing pandas directly from a git checkout (e.g. `cd pandas && python -c 'import pandas'`) without first building the editable C extensions, so that `pandas.compat` or a transitive compiled module cannot be found.

Common situations: Cloning pandas-dev/pandas and running scripts against the source tree, using `pip install -e .` without `--no-build-isolation` and a built Cython, or a CI image that skipped the build step. Also seen after a Python version bump invalidates the compiled .so files.

Related errors


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