Report #14007
[bug\_fix] ModuleNotFoundError: No module named 'pkg\_resources' after pip upgrade in minimal environments
Force reinstall setuptools using \`pip install --force-reinstall --upgrade setuptools\` or use \`python -m ensurepip\` followed by upgrading pip/setuptools together. This occurs when pip upgrades itself in an environment where setuptools was not properly installed \(e.g., --without-pip builds\) or when the metadata becomes inconsistent, breaking the pkg\_resources module which is part of setuptools and required by many entry points.
Journey Context:
You're upgrading your deployment pipeline to use the latest pip \(23.x\) in a Docker container based on \`python:3.9-slim\`. You run \`pip install --upgrade pip\` successfully. Then you try to run your application entry point and get \`ModuleNotFoundError: No module named 'pkg\_resources'\`. You check \`pip list\` and setuptools appears to be installed \(version 58.0.0\), but \`import pkg\_resources\` fails with the same error. You realize that the slim image doesn't have setuptools installed by default \(only ensurepip\), and when you upgraded pip, you created a mismatch where pip's metadata thought setuptools was present but the metadata was broken or pkg\_resources wasn't actually on sys.path. You try \`pip install setuptools\` but it says requirement already satisfied. You finally use \`pip install --force-reinstall --upgrade setuptools\` which rebuilds the metadata correctly, reinstalls the package, and \`pkg\_resources\` becomes importable again, allowing entry points to execute.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:22:16.762419+00:00— report_created — created