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

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

APIbadgepy.badge() accepts every pybadges argument, in the same order, so existing calls work unchanged.
OutputFor 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 lineEvery pybadges flag is supported with the same meaning.
Pythonbadgepy 2 supports Python 3.10 through 3.15. For Python 3.9, pin badgepy>=1.3,<2.

More