badgepy / Migrating from pybadges
pybadges fails on Python 3.13: switch to badgepy
pybadges is archived and its last release no longer imports on current Python. badgepy is its maintained fork, with the same API and the same output, so the fix is a two-line change.
The errors
On Python 3.13 and later, import pybadges stops with:
File ".../site-packages/pybadges/__init__.py", line 33, in <module>
import imghdr
ModuleNotFoundError: No module named 'imghdr'
On Python 3.12 and earlier it stops with the following, unless an older setuptools is installed:
File ".../site-packages/pybadges/precalculated_text_measurer.py", line 21, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
Why it happens
imghdrwas removed from the Python standard library in 3.13 (PEP 594).pkg_resourcescomes from setuptools, which virtual environments created with Python 3.12 or later no longer include. Current setuptools releases no longer ship it at all.- google/pybadges was archived in August 2025. Its last release, 3.0.1, dates from October 2023, so no pybadges release fixes either error.
The fix
Replace the dependency:
- pybadges==3.0.1
+ badgepy
Replace the import:
- from pybadges import badge
+ from badgepy import badge
On the command line, python -m pybadges becomes badgepy (or python -m badgepy), with the same flags.
To rename every reference in a repository at once:
git grep -l pybadges -- '*.py' | xargs perl -pi -e 's/\bpybadges\b/badgepy/g'
What stays the same
| API | badgepy.badge() accepts every pybadges argument, in the same order, so existing calls work unchanged. |
|---|---|
| Output | For the same arguments badgepy produces the same SVG as pybadges 3.0.1, so stored badges and golden-image tests keep matching. The exceptions are three bug fixes: badges with part titles, badges with a center image but no link, and badges with Chinese, Japanese or Korean text, which pybadges squeezed together. |
| Command line | Every pybadges flag is supported with the same meaning. |
| Python | badgepy 2 supports Python 3.10 through 3.15. For Python 3.9, pin badgepy>=1.3,<2. |
More
- The full migration guide lists every renamed module and every behavior change.
- Try badgepy without installing it in the playground.
- badgepy on PyPI and on GitHub.