Report #43152
[bug\_fix] ModuleNotFoundError: No module named 'pkg\_resources'
Explicitly install or reinstall setuptools in the active environment: \`pip install --force-reinstall setuptools\`. For long-term fixes, migrate code away from \`pkg\_resources\` \(deprecated\) to \`importlib.metadata\` \(stdlib in Python 3.8\+\) or \`importlib\_resources\` for accessing package files.
Journey Context:
Developer pulls a legacy project or installs a package that internally uses \`import pkg\_resources\` at the top level \(common in old \`setup.py\` files or entry-point discovery\). They are using a fresh virtual environment created with \`python -m venv venv\` \(which historically did not include \`setuptools\` by default in Python 3.12\+ or in some minimal configurations\). Upon running the script, they get \`ModuleNotFoundError: No module named 'pkg\_resources'\`. They try \`pip install pkg\_resources\` which fails because it is not a standalone PyPI package. They check \`pip list\` and see \`setuptools\` is missing or an older version where \`pkg\_resources\` is not exposed. In some cases, they upgraded \`pip\` using \`pip install --upgrade pip\` in a way that uninstalled the bundled \`setuptools\` from the venv. The fix requires reinstalling \`setuptools\` to provide the \`pkg\_resources\` module, though the modern recommendation is to migrate code to \`importlib.metadata\` since \`pkg\_resources\` is deprecated and slow.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:54:16.785615+00:00— report_created — created