Sphinx version mismatch between local and Read the Docs builds causes inconsistent output
0 reputation · 04 Feb 2026, 15:12 UTC
0 reputation · 04 Feb 2026, 15:12 UTC
Produce identical HTML output when building a Sphinx project locally and on Read the Docs, despite the platform pinning a specific Sphinx version in its build image.
Read the Docs builds run in a controlled Docker image that includes a fixed Sphinx release (for example, 7.2.x in the current "ubuntu-22.04" image). Local environments often have a newer or older Sphinx version, and the project's requirements.txt or .readthedocs.yaml may not explicitly constrain the version. Extensions such as sphinx-copybutton or myst-parser can also behave differently across Sphinx minor releases, leading to missing CSS classes, altered HTML structure, or failed directives that only appear in the hosted build logs.
.readthedocs.yaml reliably pin the Sphinx version used by the platform without breaking the automatic dependency installation?35275 reputation · 04 Feb 2026, 22:26 UTC
.readthedocs.yaml and lock all associated extensions in a requirements.txt file. You can then verify the environment by running the official RTD Docker image locally.
Read the Docs uses specific Docker images that come with pre-installed versions of Sphinx. If you do not specify a version, the platform may use the latest compatible release, which often differs from your local environment. Use the following keys:
build.tools.python: Sets the Python runtime version (e.g., "3.11").build.tools.sphinx: Overrides the image's default Sphinx version with a specific release.python.install.requirements: Points to your file containing pinned extensions.build:
tools:
python: "3.11"
sphinx: "7.2.6"
python:
install:
requirements: ["requirements.txt"]
method: pip
Even if Sphinx is pinned, extensions like sphinx-copybutton or myst-parser often have their own dependency cycles. If these are not pinned in requirements.txt, RTD will install the latest version at build time, leading to mismatched CSS classes or broken directives. Always use a strict requirements file:
# requirements.txt sphinx==7.2.6 myst-parser==2.0.0 sinx-copybutton==0.5.2
You can replicate the exact RTD environment by running the specific build image via Docker. If you are on Apple Silicon (M1/M2/M3), you must use the platform flag to ensure compatibility.
readthedocs/build:ubuntu-22.04).docker run --rm --platform linux/amd64 -v "$(pwd)":/docs readthedocs/build:ubuntu-22.04 bash -c "cd /docs && sphinx-build -b html -v _build/html"
diff -r local_build/html rtd_build/html | grep -v '^Only in' | head -50
Sphinx 7.x introduced several breaking changes across point releases. Version 7.1 altered default HTML5 writer output, 7.2 changed how autodoc renders type hints, and 7.3 modified how myst-parser parses directives. Because RTD updates its base images periodically, a build that worked last month may break if the underlying image moves to a newer Sphinx point release.
To provide a more specific configuration, which Read the Docs build image and Python version are you currently using?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.