Report #9494
[bug\_fix] ModuleNotFoundError: No module named 'pkg\_resources' \(in fresh Python 3.12\+ venv\)
Install setuptools into the virtual environment by running 'pip install setuptools', or migrate the code to use 'importlib.metadata' \(available in Python 3.8\+\) or 'importlib\_resources' instead of the deprecated 'pkg\_resources' API.
Journey Context:
You create a new virtual environment with Python 3.12 using 'python3.12 -m venv .venv' and activate it. You attempt to install a legacy package or run an internal tool that imports 'pkg\_resources' to read version metadata at startup. Immediately, you get ModuleNotFoundError: No module named 'pkg\_resources'. You check 'pip list' and notice that setuptools is not installed by default, whereas in Python 3.11 and earlier, venvs included setuptools and wheel by default. You realize that PEP 668 and changes in ensurepip/venv behavior in 3.12 removed these packages from the default venv creation to encourage use of build backends. You install 'setuptools' manually, which provides 'pkg\_resources', or you refactor the code to use 'from importlib.metadata import version' which is the modern replacement and doesn't require a third-party package in the standard library.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:18:27.454072+00:00— report_created — created