Report #94284
[bug\_fix] ModuleNotFoundError: No module named 'pkg\_resources' when importing a package
Explicitly install setuptools by running \`pip install setuptools\` in the virtual environment. For package maintainers, migrate from using \`pkg\_resources\` \(setuptools\) to \`importlib.metadata\` \(standard library\) for entry points and version detection to avoid the dependency.
Journey Context:
Developer creates a fresh virtual environment with Python 3.12 using \`python3.12 -m venv venv\`. They activate it and \`pip install\` their application. On running it, they get \`ModuleNotFoundError: No module named 'pkg\_resources'\`. They check \`pip list\` and indeed \`setuptools\` is missing. In Python 3.12, the \`venv\` module no longer includes \`setuptools\` and \`wheel\` by default \(only \`pip\`\), and \`pkg\_resources\` is part of \`setuptools\`. Many legacy packages assume setuptools is always present because it was pre-installed in older venvs. The developer realizes they must explicitly install setuptools or update the package to use \`importlib.metadata\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:50:21.944182+00:00— report_created — created