If you see ModuleNotFoundError: no module named ‘pkg_resources’ after a fresh install or a rebuilt environment, the cause is usually a newer version of setuptools. The old advice to simply run pip install setuptools no longer works, because the latest releases do not ship the module at all.
This guide explains why the error appears, how to find out which package triggers it, and the safest fixes in order: pin setuptools, update the package that needs it, or replace pkg_resources in your own code. It also covers build-time failures, Docker and CI.
What does ModuleNotFoundError: no module named ‘pkg_resources’ mean?
pkg_resources was never part of the Python standard library. It came bundled with setuptools, the packaging tool many Python projects rely on. Python is simply telling you that the installed setuptools does not contain it.
The change happened in setuptools 82.0.0, released in February 2026, which removed pkg_resources. Earlier versions kept the module but printed a warning that pkg_resources was deprecated as an API. So an environment that worked yesterday can fail today if a rebuild pulled in the newest setuptools.
Why pip install setuptools no longer fixes it
For years the standard answer was to install or upgrade setuptools. That now installs the latest release, which has no pkg_resources, so the error survives. The fix is either to install an older setuptools, or to stop depending on the removed module.
The problem is common because many older libraries import pkg_resources at import time, read their own version with it, or use it in a setup.py file. Some of these projects never declared setuptools as a dependency, so they quietly relied on it being present.
Step 1: Find where the error comes from
Before changing anything, work out which part of your setup needs the module. Run these checks in the same environment that shows the error:
python -c "import pkg_resources"
pip show setuptools
pip list
Then read the full traceback from the bottom up. It usually points to one of three places:
- Your own code imports pkg_resources directly.
- An installed dependency imports it when your program starts.
- A build step fails while pip is building a package from source, often with setuptools.build_meta in the traceback.
The right fix depends on which of these you have.
Fix 1: Pin setuptools below version 82
The fastest repair is to install a setuptools release that still includes the module:
pip install "setuptools<82"
python -c "import pkg_resources; print('ok')"
If this works, make the pin permanent so the next rebuild does not break again. Add the same constraint to your requirements.txt, your constraints file or your project dependencies:
setuptools<82
This is a short-term fix. Pinning keeps old code running, but the module is gone for good in current releases, so plan to move away from it. In a uv project, add the pin to the project dependencies instead of installing it by hand each time.
Fix 2: Update the package that needs it
If the traceback shows a third-party package, check whether a newer version has dropped pkg_resources. Many maintainers have moved to the standard library or added setuptools as an explicit dependency. Try:
pip install --upgrade name-of-package
Read the project’s release notes or issue tracker if the upgrade does not help. Some libraries are unmaintained, in which case a pin on setuptools, a maintained fork or a different library may be the only practical option.
Fix 3: Replace pkg_resources in your own code
If your own code imports pkg_resources, the lasting solution is to switch to the modern replacements. The Python documentation describes importlib.metadata as the replacement for the metadata and entry point features, and importlib.resources covers package data files. importlib.metadata has been in the standard library since Python 3.8.
| Old pkg_resources call | 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.parse_version(“1.2”) | packaging.version.Version(“1.2”) |
| pkg_resources.resource_string(“pkg”, “file”) | importlib.resources.files(“pkg”).joinpath(“file”).read_bytes() |
Here is a typical before and after for reading a package version:
# Before
import pkg_resources
version = pkg_resources.get_distribution("requests").version
# After
from importlib.metadata import version
current = version("requests")
The packaging library is a separate install, so add it to your dependencies if you use packaging.version. Setuptools keeps its own notes on the module in its pkg_resources documentation.
Fix 4: Build-time errors while installing a package
Sometimes the error appears while pip builds a package from source, because that package’s setup.py imports pkg_resources. A common example is a setup.py that uses pkg_resources.parse_version. Pip builds in an isolated environment by default, so the setuptools you pinned in your main environment is not used.
These are the usual options:
- Install a newer release of the package, if its maintainers have fixed the build.
- Install a wheel instead of building from source when one is available.
- Pin setuptools in your environment, then install the package with build isolation turned off:
pip install "setuptools<82" wheel pip install --no-build-isolation name-of-package - If you maintain the package, replace pkg_resources.parse_version with packaging.version.parse and add packaging to the build requirements.
Docker, CI and virtual environments
These errors often surface in automated builds because a clean image installs the newest setuptools every time. A few habits keep builds stable:
- Pin setuptools in the Dockerfile or the lock file, for example RUN pip install –no-cache-dir “setuptools<82”.
- Use a lock file or constraints file so every build resolves the same versions.
- Rebuild virtual environments from scratch after changing pins, instead of patching them in place.
- Test dependency upgrades in a separate branch before they reach production.
The same discipline matters on servers. Our piece on migrating physical servers to Proxmox VE shows how much easier rebuilds are when the environment is documented, and our look at why hosting stability matters makes a similar case for predictable setups.
Things to avoid
- Do not keep running pip install setuptools and hoping it changes. It installs the same version without the module.
- Do not copy pkg_resources files from an old environment into a new one.
- Do not install random packages named after the module. Stick to setuptools versions.
- Do not ignore the warning on older setuptools. It is the early notice that this error is coming.
- Do not leave the pin undocumented. Add a comment explaining why it exists, so a future update does not remove it by accident.
A short checklist
- Run python -c “import pkg_resources” to confirm the problem.
- Check the setuptools version with pip show setuptools.
- Read the traceback to find out whether your code, a dependency or a build step is responsible.
- Pin setuptools below 82 to restore service.
- Upgrade or replace the package that depends on pkg_resources.
- Migrate your own code to importlib.metadata, importlib.resources and packaging.
- Lock the versions in your requirements and build files.
If you work with automation tools, our overview of AI tools that analyze charts and tables in PDF documents shows how quickly small Python-based tools can pile up dependencies.
Frequently asked questions
Why did this error start appearing suddenly?
Setuptools 82.0.0 removed pkg_resources in February 2026. Environments that were rebuilt or installed fresh began pulling the newest setuptools, so code that depended on the module stopped working even though nothing in your own project changed.
Can I install pkg_resources with pip?
No. pkg_resources was always part of setuptools, not a separate package you should install. Pin setuptools to a version below 82 if you need it, or move your code to importlib.metadata and importlib.resources instead.
Is pinning setuptools below 82 safe?
It is a reasonable short-term fix that restores the module. It keeps old code running, but it also keeps you on an older tool. Use it to unblock builds, then update dependencies or rewrite imports so you can drop the pin.
Why does the error appear only during pip install?
The package you are installing probably imports pkg_resources in its setup.py, and pip builds it in an isolated environment with the newest setuptools. Install a fixed release, use a wheel, or pin setuptools and install with the no-build-isolation option.
What replaces pkg_resources.get_distribution?
Use importlib.metadata.version(“name”) to read a package version, or importlib.metadata.distribution(“name”) for fuller metadata. Both are part of the standard library from Python 3.8, so they work without any extra install.
Does this affect virtual environments and Docker images?
Yes. Any environment that installs the latest setuptools can hit it. Pin setuptools in your requirements or Dockerfile, rebuild the environment cleanly, and use a lock file so every build installs the same versions.
Conclusion
The error ModuleNotFoundError: no module named ‘pkg_resources’ comes from setuptools 82 dropping a module that older code still expects. Pin setuptools below 82 to get back to work, then update the package that needs it or migrate your own imports to importlib.metadata, importlib.resources and packaging. Lock your versions so the problem does not return.

Doris Pollard, a mesmerizing wordsmith and experienced blogger, crafts narratives that carry readers into unexplored realms. Infused with insightful perspectives and vibrant storytelling, Doris’s mastery of language captivates both hearts and minds, making an enduring impression on the literary landscape.