Report #73633
[bug\_fix] ModuleNotFoundError: No module named 'pkg\_resources'
Install setuptools into the environment: \`pip install setuptools\`. For modern code, replace the import with \`importlib.metadata\` \(standard library in Python 3.8\+\) or \`importlib\_resources\` for file access. Root cause: \`pkg\_resources\` is part of setuptools, which is no longer guaranteed to be installed in all environments \(e.g., minimal containers, venvs created with --without-pip, or Python 3.12\+ where setuptools is not pre-installed in venvs\). The Python community has moved to importlib.metadata per PEP 566.
Journey Context:
You created a fresh virtual environment using \`python3.12 -m venv venv\` on a minimal Docker image \(python:3.12-slim\). You activate it and try to run a legacy script that uses \`pkg\_resources.require\('mypackage'\)\` to check versions. It crashes with ModuleNotFoundError: No module named 'pkg\_resources'. You check \`pip list\` and see only pip and wheel, no setuptools. You realize that modern venvs or minimal containers may not include setuptools by default, or you used \`--without-pip\` earlier. You try \`pip install setuptools\` but get 'pip: command not found' because you didn't install pip in the venv. You recreate the venv properly with \`python3 -m venv venv\` \(which includes pip and setuptools by default in standard builds\). After activating, you install setuptools and the import works. You note to modernize the code to use \`importlib.metadata\` instead to avoid the dependency on setuptools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:11:26.839665+00:00— report_created — created