Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› Error when building documentation with Python 3.13+ (No module named 'imghdr') #229

Closed
ebouchut opened this issue Feb 20, 2025 · 0 comments Β· Fixed by #230
Closed

Comments

@ebouchut
Copy link
Contributor

ebouchut commented Feb 20, 2025

Description

❌ Since Feb 17, the documentation.yaml workflow has been failing repeatedly with this error:

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

Run sphinx-build -b dirhtml docs _build
sphinx-build -b dirhtml docs _build
shell: /usr/bin/bash -e {0}
env:
  pythonLocation: /opt/hostedtoolcache/Python/3.13.2/x64
  LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.13.2/x64/lib
Running Sphinx v5.3.0

Extension error:
Could not import extension sphinx.builders.epub3 (exception: No module named 'imghdr')
Error: Process completed with exit code 2.

Cause

The imghdr module has been removed from the Python Standard Library as of Python 3.13, following its deprecation in Python 3.11.

The documentation.yaml GitHub workflow highlighted this bug as it uses Python v3.13+.
I reproduced the bug locally after upgrading Python to version 3.13 and attempting to build the documentation.
Therefore, this is not a CI/CD bug.

➑️ The cause is the outdated package(s) using the ìmghdr` module that no longer exists as of Python 3.13+.

cd nighscout.github.io

pyenv install 3.13.2
pyenv local 3.13.2

python  -m venv venv
pip install -r requirements.txt

rm -rf _build
sphinx-build -M dirhtml docs/ _build/

#=> Running Sphinx v5.3.0
#=>
#=> Extension error:
#=> Could not import extension sphinx.builders.epub3 (exception: No module named 'imghdr')

Solution

A quick search led me to conclude that sphinx version 5.3 is the only package that uses it.

grep -r imghdr venv/lib/python3.13/site-packages/

Binary file venv/lib/python3.13/site-packages//sphinx/util/__pycache__/images.cpython-313.pyc matches
venv/lib/python3.13/site-packages//sphinx/util/images.py:import imghdr
venv/lib/python3.13/site-packages//sphinx/util/images.py:    imgtype = imghdr.what(stream)
venv/lib/python3.13/site-packages//sphinx/util/images.py:    """An additional imghdr library helper; test the header is SVG's or not."""
venv/lib/python3.13/site-packages//sphinx/util/images.py:# install test_svg() to imghdr
venv/lib/python3.13/site-packages//sphinx/util/images.py:# refs: https://docs.python.org/3.6/library/imghdr.html#imghdr.tests
venv/lib/python3.13/site-packages//sphinx/util/images.py:imghdr.tests.append(test_svg)

🎯 So, I suggest updating the project packages/dependencies:

@ebouchut ebouchut changed the title GitHub Workflow Error: No module named 'imghdr' πŸ’” GitHub Workflow Error: No module named 'imghdr' Feb 20, 2025
@ebouchut ebouchut changed the title πŸ’” GitHub Workflow Error: No module named 'imghdr' πŸ› Error when building documentation with Python 3.13+ (No module named 'imghdr') Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant