Trac 1.6: No module named 'pkg_resources' (tested fix)

Trac 1.6, the latest release, does from pkg_resources import ... in trac/__init__.py, so on setuptools 82 or newer trac-admin, tracd and the WSGI app fail with ModuleNotFoundError: No module named 'pkg_resources'. Tested fix: pip install "setuptools<81".

1. The error: Trac 1.6 with setuptools 84

pip install Trac (1.6, the newest release, from 2023-09-23) into a Python 3.11.17 venv with setuptools 84.2.1:

$ trac-admin --version
Traceback (most recent call last):
  File "/path/to/venv/bin/trac-admin", line 4, in <module>
    from trac.admin.console import run
  File "/path/to/venv/lib/python3.11/site-packages/trac/__init__.py", line 14, in <module>
    from pkg_resources import DistributionNotFound, get_distribution
ModuleNotFoundError: No module named 'pkg_resources'

Line 14 of trac/__init__.py is from pkg_resources import DistributionNotFound, get_distribution, with no fallback. setuptools 82.0.0 removed pkg_resources. Trac declares setuptools>=30.3 with no upper bound, so pip happily keeps or installs a setuptools that breaks it. Every Trac entry point (trac-admin, tracd, the WSGI app) imports this module first.

2. Fix: pin setuptools below 81 (tested)

$ pip install "setuptools<81"    # gave 80.10.2
$ trac-admin --version
/path/to/venv/lib/python3.11/site-packages/trac/__init__.py:14: 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 DistributionNotFound, get_distribution
trac-admin 1.6

Trac works again. With the pin, trac-admin /path/env initenv demo sqlite:db/trac.db also created a new environment in our test. The pkg_resources is deprecated as an API warning stays; hide it with:

$ PYTHONWARNINGS="ignore:pkg_resources is deprecated as an API" trac-admin --version
trac-admin 1.6

For tracd or mod_wsgi, set the same PYTHONWARNINGS value in the service's environment.

3. No fixed release yet

We checked the Trac trunk on GitHub (edgewall/trac, last commit 2026-09-27, version 1.7.1 dev): trac/__init__.py still has the same unguarded import. So upgrading Trac does not help yet; keep the pin in your requirements file or Dockerfile so a later pip install -U setuptools doesn't undo it.

Related: No module named 'pkg_resources' (general fix) · import fs (same problem in a latest release) · Odoo 16.

Frequently asked questions

Is there a Trac release that fixes it?

Not as of 2026-10-24: 1.6 is the newest release on PyPI, and the trunk on GitHub (1.7.1 dev) still has the unguarded import.

Does pinning setuptools affect Trac plugins?

It keeps pkg_resources available, which Trac and older plugins use for plugin discovery, so they behave as before. You only get a deprecation warning.

Written with AI assistance. Measured on 2026-10-24 on Linux with Trac 1.6, CPython 3.11.17, setuptools 80.10.2 and 84.2.1. Output pasted unedited except shortened paths. PlainTables is our extension; Trac is free.