Sphinx "Could not import extension" build error in CI
Sphinx tried to load an extension named in extensions in conf.py and the import failed. Almost always the package that provides it was not installed in the CI environment.
What this error means
sphinx-build aborts at startup with "Could not import extension X (exception: No module named 'X')" before any page is rendered.
sphinx-build
Extension error:
Could not import extension sphinx_rtd_theme (exception: No module named 'sphinx_rtd_theme')Common causes
The extension package is not installed in CI
conf.py lists the extension in extensions, but the distribution that provides it is missing from the docs requirements the runner installed.
A different interpreter or venv than expected
CI installed the extension into one environment but runs sphinx-build from another, so the import path does not include it.
How to fix it
Install the extension in the docs environment
- Match the import name in the error to its distribution name.
- Add it to your docs requirements file.
- Install that file in CI before running sphinx-build.
Terminal
pip install -r docs/requirements.txt
sphinx-build -b html docs docs/_build/htmlPin docs dependencies in one file
Keep every extension your conf.py loads in a single requirements file so the runner installs them all.
docs/requirements.txt
# docs/requirements.txt
sphinx>=7
sphinx-rtd-theme
myst-parserHow to prevent it
- List every extension from conf.py in your docs requirements.
- Install docs requirements into the same interpreter that runs sphinx-build.
- Pin extension versions so behavior is reproducible.
Related guides
Sphinx "Theme error: no theme named" build failure in CIFix Sphinx "Theme error: no theme named X found" in CI - html_theme in conf.py names a theme whose package is…
Sphinx autodoc "failed to import module" in CIFix Sphinx "autodoc: failed to import module X" in CI - autodoc imports your package to read docstrings, and…
Read the Docs build failed installing requirements in CIFix Read the Docs builds that fail while installing requirements - the python.install step did not point at t…