If you see ModuleNotFoundError: no module named ‘pkg_resources’, your Python environment is missing the module, and the most likely reason is that you installed setuptools 82 or newer. That release removed pkg_resources, so code that still imports it fails at startup or during a package install.
The fastest fix is to pin setuptools below version 82 in the environment that is failing. The better long-term fix is to stop using pkg_resources and switch to the modern standard-library tools. This guide explains the cause, the quick fixes and the code changes for package authors.
What the error means
The full message usually looks like this:
ModuleNotFoundError: No module named 'pkg_resources'
It means Python tried to run import pkg_resources and could not find the module. For years, pkg_resources shipped inside setuptools, so any environment with setuptools had it. Libraries used it to look up package versions, load entry points and read data files.
Setuptools has discouraged that for a long time. The change log states that the removal happened in version 82.0.0, released on February 8, 2026. The note says most common uses have been replaced by importlib.resources and importlib.metadata, and that projects depending on pkg_resources for namespace packages or other behavior should depend on older versions of setuptools. You can read the entry in the setuptools release history.
Common causes
- Setuptools 82 or newer is installed. A fresh virtual environment or a Docker build pulled the latest version, which no longer includes pkg_resources.
- A package still imports pkg_resources. Older libraries and build scripts such as a setup.py file may call it at import time.
- Setuptools is missing entirely. New virtual environments on recent Python versions do not always include setuptools, so nothing provides the module.
- Build isolation installs the newest setuptools. When pip builds a package from source, it creates a temporary environment and fetches the latest setuptools unless the project pins it.
The last case catches many people. Your own environment may have a working older setuptools, but the isolated build environment does not, so the install fails even though import pkg_resources works in your shell.
Step 1: Confirm the cause
Run these commands in the environment that is failing:
python -m pip show setuptools
python -c "import pkg_resources; print(pkg_resources.__file__)"
python --version
If setuptools is version 82.0.0 or higher, or the package is not installed, the diagnosis is confirmed. If the error appears only during pip install and not in a normal shell, the cause is probably build isolation.
Step 2: Pin setuptools below 82
This is the quickest fix for an existing project, and it is exactly what many maintainers did when the change landed.
python -m pip install "setuptools<82"
Then try your command again. To make the fix permanent, add the pin to your project files:
# requirements.txt
setuptools<82
# pyproject.toml (if you build the project)
[build-system]
requires = ["setuptools<82", "wheel"]
build-backend = "setuptools.build_meta"
For Docker images and CI pipelines, add the pin before the install step. That way a rebuild next month will not break your deployment when a new release comes out.
Step 3: Fix failing source installs
If pip fails while building a package that imports pkg_resources in its setup.py, disable build isolation after installing the older setuptools:
python -m pip install "setuptools<82" wheel
python -m pip install --no-build-isolation package-name
This tells pip to use the setuptools already in your environment rather than downloading the newest one. It is a good workaround for abandoned packages that nobody has updated. If you use another installer such as uv, check its documentation for the equivalent setting, because the option names differ.
Step 4: Replace pkg_resources in your code
If you maintain the code that fails, the real fix is to remove the dependency. The standard library offers replacements for the most common uses. See the Python documentation for importlib.metadata for the full API.
| Old code | Modern replacement |
|---|---|
pkg_resources.get_distribution("pkg").version |
importlib.metadata.version("pkg") |
pkg_resources.iter_entry_points("group") |
importlib.metadata.entry_points(group="group") |
pkg_resources.resource_string("pkg", "file") |
importlib.resources.files("pkg").joinpath("file").read_bytes() |
pkg_resources.parse_version(v) |
packaging.version.parse(v) |
Here is a small before and after example for reading a package version:
# Before
import pkg_resources
version = pkg_resources.get_distribution("requests").version
# After
from importlib.metadata import version
version = version("requests")
The packaging library is a separate package, so add it to your dependencies if you use packaging.version.parse. The entry_points(group=...) form needs Python 3.10 or newer, so on older versions use the importlib_metadata backport.
Namespace packages and old plugin systems
Some projects used pkg_resources to declare namespace packages with declare_namespace. The modern approach is implicit namespace packages, where you simply leave out the __init__.py file in the shared directory. Plugin systems that used iter_entry_points can move to importlib.metadata.entry_points.
These changes are small for a single project, but they can ripple through a dependency tree. If a third-party library still needs pkg_resources, open an issue or check whether a newer release or fork has already fixed it.
Other places this error appears
The same error can show up in tools that run Python for you. Deployment platforms, bench tools and build systems have all reported failures after the removal, usually because they created a fresh environment with the latest setuptools. The fix is the same: pin setuptools in the tool’s environment or update the app to a release that no longer imports pkg_resources.
If you are setting up a low-cost learning device for coding practice, our guide on how to apply for a free tablet from the government explains what support exists. You can also browse more practical guides on Servioza.
How to prevent the error in future projects
- Pin your build tools in
pyproject.tomland your runtime dependencies in a lock file. - Run your test suite against the newest setuptools in CI, so you see problems before users do.
- Replace pkg_resources imports as part of regular maintenance.
- Use a recent Python version and check whether your dependencies support it.
Treat the pin as a temporary patch. Older setuptools versions stop getting fixes over time, and newer Python versions may stop supporting them, so a migration plan is worth writing down.
Frequently asked questions
Why did pkg_resources suddenly disappear?
Setuptools 82.0.0, released in February 2026, removed it after years of warnings. A new environment that installs the latest setuptools no longer includes pkg_resources, so code that imports it fails until you pin an older version or update the code.
Can I just install pkg_resources with pip?
No. It was never a separate package. It shipped inside setuptools. Installing an older setuptools release brings it back, which is why the usual fix is to pin setuptools below version 82.
Which setuptools version should I pin?
Pin below 82, for example setuptools<82. Any 81.x or older release still includes pkg_resources. Pick the newest one that works for your stack, and check that it supports your Python version.
Why does the error appear only during pip install?
Pip builds source packages in an isolated environment that downloads the latest setuptools. Install an older setuptools yourself and run pip with --no-build-isolation, or ask the package maintainer to pin setuptools in the build settings.
What replaces pkg_resources in modern Python?
Use importlib.metadata for versions and entry points, importlib.resources for data files and the packaging library for version parsing. These tools are maintained and work without setuptools installed.
Does this affect Python 3.12 and newer?
It can. Newer virtual environments may not include setuptools at all, and the latest setuptools has no pkg_resources. Either way, pinning an older setuptools or moving to importlib is the dependable fix.
Conclusion
The ModuleNotFoundError for pkg_resources means setuptools 82 or newer removed the module. Pin setuptools below 82 to get unstuck quickly, use no-build-isolation for stubborn installs and migrate your code to importlib.metadata, importlib.resources and packaging. That approach protects every future build.

Lily Rose is a passionate food blogger with years of experience exploring menus, flavors, and dining trends, delivering clear, reliable insights that help readers discover great food and make confident choices.