{"record":{"id":"31d91193dd7de3ad","repo":"pandas-dev/pandas","slug":"c-extension-module-not-built-if-you-want-to-i","errorCode":null,"errorMessage":"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.","messagePattern":"C extension: (.+?) 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\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"pandas/__init__.py","lineNumber":27,"sourceCode":"for _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.\"\n    ) from _err\n\nfrom pandas._config import (\n    get_option,\n    set_option,\n    reset_option,\n    describe_option,\n    option_context,\n    options,\n)\n\n# let init-time option registration happen\nimport pandas.core.config_init  # pyright: ignore[reportUnusedImport] # noqa: F401\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/__init__.py#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Build the extensions in place: `python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true` (the exact command in the message).","Ensure build deps are present first: `python -m pip install meson-python meson ninja Cython>=3.0.0 versioneer`.","Alternatively install a released wheel: `python -m pip install pandas` (no build needed).","Run `python setup.py build_ext --inplace` only on legacy branches; modern main uses Meson via the editable install command above."],"exampleFix":"# before\n$ python -c \"import pandas\"  # C extension: pandas._libs not built\n\n# after\n$ python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true\n$ python -c \"import pandas; print(pandas.__version__)\"","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec(\"pandas._libs\") is None:\n    raise SystemExit(\"pandas C extensions not built; run: python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["For source development always run the documented editable-install command first.","Keep build deps (meson, meson-python, ninja, Cython) installed in the dev env.","After a Python upgrade, rebuild editable installs before importing pandas."],"tags":["import","build","c-extension","editable-install","cython"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}