Fixing “No module named 'pkg_resources'” After Setuptools 82 Removal

Experienced Software Engineer proficient in Python, Django, ReactJS, and Next.js, with expertise in web scraping. Dedicated to developing robust web applications, I specialize in integrating cutting-edge technologies to innovate and optimize efficiency.
In February 2026, Setuptools v82.0.0 officially removed the pkg_resources module. Many existing Python projects still depend on pkg_resources, so upgrading to the latest Setuptools can suddenly cause the error:
ModuleNotFoundError: No module named 'pkg_resources'
This article explains why the error occurs, how to fix it immediately, and how to prevent it in future deployments.
Why This Error Happens
Before Setuptools 82.0.0, the pkg_resources module was bundled with Setuptools and automatically available in Python environments.
Starting from v82.0.0 (Feb 2026):
pkg_resourceswas removedDevelopers are encouraged to use:
importlib.resourcesimportlib.metadata
However, many legacy libraries and internal tools still import:
import pkg_resources
When environments install the latest Setuptools, the module is no longer present, resulting in the error.
Quick Fix (Recommended for Existing Projects)
If your project or dependencies still rely on pkg_resources, install a Setuptools version below 82.
requirements.txt fix
setuptools<=80.10.2
Then reinstall dependencies:
pip install -r requirements.txt
or manually:
pip install "setuptools<=80.10.2"
This restores the pkg_resources module.
Important: Avoid This Common Mistake
Do NOT use:
setuptools>=80.10.2
because this allows pip to install Setuptools 82+, which removes pkg_resources and recreates the error.
Always pin using:
setuptools<=80.10.2
(or any version below 82, depending on project compatibility)
Docker Fix Example
If using Docker, explicitly install the compatible version:
RUN pip install --no-cache-dir "setuptools<=80.10.2"
This prevents future image rebuilds from breaking when newer versions are released.
Long-Term Recommended Solution (Future-Proof)
Since pkg_resources is now removed, projects should gradually migrate to:
Instead of:
import pkg_resources
version = pkg_resources.get_distribution("mypackage").version
Use:
from importlib.metadata import version
version = version("mypackage")
For file access:
from importlib.resources import files
This ensures compatibility with future Python environments.
Best Practice for Production Systems
To avoid unexpected dependency failures:
Pin Setuptools in requirements.txt
Lock dependencies using:
pip freezePoetry lock file
pip-tools
Rebuild Docker images regularly and test dependency upgrades safely
Final Recommendation
Until all dependent libraries migrate away from pkg_resources, use:
setuptools<=80.10.2
instead of:
setuptools>=80.10.2
This simple version pinning prevents the “No module named 'pkg_resources'” error across local environments, CI pipelines, and Docker deployments.
Source: https://setuptools.pypa.io/en/stable/history.html#v82-0-0 https://setuptools.pypa.io/en/stable/history.html#v67-3-2


