Skip to content

Conversation

@tgaspar
Copy link
Contributor

@tgaspar tgaspar commented Oct 17, 2025

Summary

This PR adds the standard-imghdr dependency to requirements.txt to make build compatible in newer (>3.13) Python environments while at the same time abiding to the sphinx==5.0.

When building the Sphinx documentation with the sphinxdoc/sphinx Docker image (same happens when using the latest Python image) I noticed errors stating that a Python module was missing:

Could not import extension sphinx.builders.epub3 (exception: No module named 'imghdr')

This error does not appear in CI because the Github build pipeline uses an older version of Python:

    - uses: actions/setup-python@v6
      with:
        python-version: '3.8'
        cache: 'pip'

The module imghdr has been deprecated in Python 3.11 and completely removed in Python 3.13 (see Removed Modules and PEP 0594.

Reproducing the error

To reproduce the issue:

Navigate to the docs directory and start the Python (or Sphinx) Docker container (for Sphinx replace python:3 with sphinxdoc/sphinx):

docker run -it -v `pwd`:/docs --rm python:3 /bin/bash

Then, inside the Docker, install the dependencies:

cd /docs; pip3 install -r requirements.txt

Finally, try building the documentation with (you're already in the docs directory):

make html

The result should be the following error

Running Sphinx v5.0.0

Extension error:
Could not import extension sphinx.builders.epub3 (exception: No module named 'imghdr')
make: *** [Makefile:26: html] Error 2

Then, manually try manually installing standard-imghdr:

pip3 install standard-imghdr

Try rebuilding now and the error is gone.

Backwards compatibility

To test backwards compatibility, checkout this branch that adds standard-imghdr to the requirements.txt file. Then, repeat the process described above with an older version of Python. For instance, use the image for Python 3.8:

docker run -it -v `pwd`:/docs --rm python:3.8 /bin/bash

Additional note

This error arises mainly due to defining relatively old versions of both Sphinx (==5.0) and Python (==3.8). I also tested building the documentation with a newer version of Sphinx and did not notice any build errors. However, I think that adding standard-imghdr to the requirements.txt is a smaller change and less likely to disrupt anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant