{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/__init__.py#L9-L45","documentation":"Raised when importing `pandas.compat` (or its transitive C-extension submodule named in `_err.name`) fails with an ImportError during pandas init. This almost always means a compiled extension inside pandas itself was not built, which happens with an editable/source checkout that was never compiled. The message points at the exact build command pandas recommends.","triggerScenarios":"Running `import pandas` from a source clone after `pip install -e .` (or just adding the dir to sys.path) without having compiled the Cython/C extensions; the `from pandas.compat import is_numpy_dev` line at pandas/__init__.py:22 triggers a deeper C-extension import that fails.","commonSituations":"Developer checkout without a build step; missing build toolchain (Cython, compiler, numpy headers) during install; stale build artifacts after a git pull that added new extensions; `--no-build-isolation` used incorrectly so build deps were absent.","solutions":["Run the exact command in the message: `python -m pip install -ve . --no-build-isolation -Ceditable-verbose=true` from the repo root.","Ensure build prerequisites are present: `pip install setuptools wheel Cython numpy` and a working C compiler.","Clean stale artifacts then rebuild: remove `build/` and any `*.so`/`*.pyd`, then reinstall.","If you did not intend an editable install, do a normal `pip install pandas` (or uninstall the editable version first)."],"exampleFix":"// before\ncd pandas-source && pip install -e .\npython -c \"import pandas\"\n# ImportError: C extension: ... not built. ...\n\n// after\npython -m pip install -ve . --no-build-isolation -Ceditable-verbose=true\npython -c \"import pandas; print(pandas.__version__)\"","handlingStrategy":"validation","validationCode":"import importlib.util, sys\ndef pandas_extensions_built() -> bool:\n    # the import that triggers the C-extension load path\n    try:\n        import pandas.compat  # noqa: F401\n        return True\n    except ImportError:\n        return False\n# in dev setup scripts: build first, then assert this is True","typeGuard":"null","tryCatchPattern":"try:\n    import pandas\nexcept ImportError as e:\n    if 'C extension' in str(e) and 'not built' in str(e):\n        # run the documented build command, then retry\n        ...\n    raise","preventionTips":["After `git pull`, rebuild editable installs: `pip install -ve . --no-build-isolation -Ceditable-verbose=true`.","Keep build deps installed: `pip install Cython numpy setuptools` plus a C compiler.","Remove stale `build/` and compiled artifacts before rebuilding.","Use `python setup.py build_ext --inplace` only as a secondary dev option."],"tags":["c-extension","build","editable-install","development","cython","compiler"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}