pygame: pkg_resources is deprecated as an API (tested fix)

pygame 2.6.1 prints UserWarning: pkg_resources is deprecated as an API from pygame/pkgdata.py:25 when it loads its default font. Tested fix: upgrade setuptools (pygame falls back cleanly when pkg_resources is gone), or silence it with PYTHONWARNINGS.

1. The warning: pygame 2.6.1 with setuptools 80

import pygame on its own printed no warning. It appeared as soon as pygame loaded its bundled default font. Our b1.py:

import pygame
pygame.font.init()
font = pygame.font.Font(None, 20)
print("font ok")
$ python -c "import setuptools; print('setuptools', setuptools.__version__)"
setuptools 80.10.2
$ PYGAME_HIDE_SUPPORT_PROMPT=1 python b1.py
/path/to/venv/lib/python3.11/site-packages/pygame/pkgdata.py:25: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import resource_stream, resource_exists
font ok

pygame/pkgdata.py tries from pkg_resources import ... inside try/except ImportError and falls back to plain file paths when the import fails.

2. Fix: upgrade setuptools (counterintuitive, tested)

Because pygame has that fallback, newer setuptools, which no longer has pkg_resources, makes the warning go away and the font still loads:

$ pip install -U setuptools
$ python -c "import setuptools; print('setuptools', setuptools.__version__)"
setuptools 84.2.1
$ PYGAME_HIDE_SUPPORT_PROMPT=1 python b1.py
font ok

Check first that nothing else in the environment needs pkg_resources, because on setuptools 82 or newer those imports raise No module named 'pkg_resources'.

3. Or keep setuptools and silence it

$ PYGAME_HIDE_SUPPORT_PROMPT=1 PYTHONWARNINGS="ignore:pkg_resources is deprecated as an API" python b1.py
font ok

The in-code version (warnings.filterwarnings before importing pygame) is in the general guide to this warning. PYGAME_HIDE_SUPPORT_PROMPT=1 only hides pygame's "Hello from the pygame community" banner, not this warning.

Frequently asked questions

Will upgrading setuptools break pygame?

Not in our test: pygame 2.6.1 with setuptools 84.2.1 loaded the default font with no warning, because pkgdata.py catches the ImportError and uses file paths.

Does PYGAME_HIDE_SUPPORT_PROMPT hide the warning?

No, it only hides the 'Hello from the pygame community' banner. Use PYTHONWARNINGS or warnings.filterwarnings for the pkg_resources warning.

Written with AI assistance. Measured on 2026-10-24 on Linux with pygame 2.6.1 (SDL 2.28.4), CPython 3.11.17, setuptools 80.10.2 and 84.2.1. Scripts and output pasted unedited except shortened paths. PlainTables is our extension; pygame is free.