If you have just seen ModuleNotFoundError: no module named ‘pkg_resources’ in your terminal, the cause is almost always your setuptools version. The module pkg_resources used to ship inside setuptools, and recent setuptools releases removed it. Any script or package that still imports it now fails the moment Python tries to load it.
The good news is that the error is easy to fix once you know why it happens. This guide covers the quick fix, the safer long-term fix, and the code changes that remove the problem for good.
What ModuleNotFoundError: no module named ‘pkg_resources’ means
The message means Python cannot find a module called pkg_resources in the environment you are using. It is not part of the Python standard library. It was a component of the setuptools package, so it only exists when a compatible version of setuptools is installed.
Two things have changed in recent years, and both can trigger the error:
- Setuptools removed the module. Setuptools 82.0.0, released on 8 February 2026, removed pkg_resources entirely. The project had announced a deadline for removal in an earlier release, and the module had been deprecated for a long time before that.
- New environments often start without setuptools. Since Python 3.12, a freshly created virtual environment no longer includes setuptools by default. If a package expects it to be there, you must install it yourself.
The error usually appears when you run an older script, install an older package, or build a package from source. It is rarely a problem with your own code unless you wrote the import yourself.
Quick fix: install a compatible setuptools
The fastest fix is to install a version of setuptools that still contains pkg_resources. Use a version below 82:
python -m pip install "setuptools<82"
Run this inside the same environment where the error appears. If you use conda, the equivalent is:
conda install "setuptools<82"
Then run your script again. If the error disappears, you have confirmed that an old import was the cause. Note that simply running pip install setuptools without a limit installs the newest version, and that version will not contain the module.
How to check your current setuptools version
You can confirm what is installed with either of these commands:
python -m pip show setuptools
python -c "import setuptools; print(setuptools.__version__)"
If pip reports that setuptools is not found, the package is missing from that environment. If the version is 82 or higher, pkg_resources is gone and you need to pin an older release or update the code that imports it.
Common causes and the matching fix
| Situation | Likely cause | Best fix |
|---|---|---|
| Old script fails on import | Script imports pkg_resources | Pin setuptools below 82, then update the script |
| New virtual environment | Python 3.12 or later has no setuptools by default | Install a compatible setuptools |
| Error during pip install | Package’s build step needs pkg_resources | Use a build without isolation, or update the package |
| Third-party app breaks after upgrade | Package depends on removed module | Upgrade the package, or pin setuptools until it is fixed |
| Your own code imports it | Old import style | Switch to importlib.metadata or importlib.resources |
Fixing the error during pip install
Many people meet this error while installing a package, not while running code. In that case the failure happens inside the temporary build environment that pip creates. That environment downloads the newest setuptools, so a package whose setup file still imports pkg_resources fails right away.
Try these steps in order:
- Upgrade the package to a newer release, because many maintainers have already removed the old import.
- Install a compatible setuptools in your environment first:
python -m pip install "setuptools<82" wheel. - Run the install again without build isolation so pip uses the setuptools you just installed:
python -m pip install --no-build-isolation package-name. - If the package is no longer maintained, consider an alternative, or fork it and update the import.
The no-build-isolation option is a workaround, not a permanent answer. It is best used for a single stubborn package while you wait for an upstream fix.
Replace pkg_resources in your own code
If the import is in code you control, the lasting fix is to stop using pkg_resources. The standard library now covers the most common jobs. Setuptools itself points developers to importlib.resources and importlib.metadata as the replacements.
Get an installed package version
Old code:
import pkg_resources
version = pkg_resources.get_distribution("requests").version
New code:
from importlib.metadata import version
v = version("requests")
Read a file bundled inside a package
Old code:
import pkg_resources
path = pkg_resources.resource_filename("mypkg", "data/config.json")
New code:
from importlib.resources import files
path = files("mypkg") / "data" / "config.json"
Find plugins with entry points
Old code:
import pkg_resources
for ep in pkg_resources.iter_entry_points("my.plugins"):
plugin = ep.load()
New code:
from importlib.metadata import entry_points
for ep in entry_points(group="my.plugins"):
plugin = ep.load()
Compare version numbers
Some projects used from pkg_resources import packaging to compare versions. Install the separate packaging library and import from it directly:
from packaging.version import parse
if parse("2.1.0") > parse("2.0.5"):
print("newer")
After you make these changes, you no longer need to pin setuptools, and your project works on both old and new Python setups.
Why not just pin setuptools forever?
Pinning setuptools below 82 is a sensible short-term step, but it has costs. You may miss security fixes and bug fixes in newer releases, and newer Python versions can eventually stop working with older build tools. Treat the pin as a bridge while you update the packages that rely on the old module.
For the full list of changes, including the release that removed the module, read the setuptools release history. It also shows which versions still include pkg_resources, which helps if you need to choose a specific pin.
Prevent the error in future projects
- List setuptools explicitly in your requirements only if you truly need it, and note the version limit in a comment.
- Run a quick search of your project for the text pkg_resources before upgrading your tools.
- Create a fresh virtual environment for each project so a global change does not break old work.
- Keep dependencies up to date so maintainers’ fixes reach you early.
- Test new Python or setuptools releases in a separate environment before upgrading production machines.
Looking for more practical how-to guides while you troubleshoot? Our walkthrough on how to apply for a free tablet from the government and our explainer on how big a 65 inch TV is are good examples of straightforward technology answers.
Frequently asked questions
Why did pkg_resources disappear from my Python environment?
Setuptools 82.0.0 removed the module, and new virtual environments on Python 3.12 or later do not include setuptools by default. If you upgraded setuptools or created a fresh environment, the module is no longer there until you install a compatible version.
Does pip install setuptools fix the pkg_resources error?
Not always. Running the plain command installs the newest setuptools, and that release no longer contains the module. Use pip install "setuptools<82" to get a version that still includes it, then plan to update the code that imports it.
Is pkg_resources part of the Python standard library?
No. It was part of the third-party setuptools package. That is why it can be missing from a clean environment and why its availability depends on which setuptools version you have installed.
What replaces pkg_resources in modern Python?
For most tasks, use importlib.metadata to read package versions and entry points, and importlib.resources to access files bundled inside packages. For version comparisons, use the separate packaging library. These are the recommended replacements.
How do I fix the error when installing a package with pip?
Upgrade the package first. If that is not possible, install a compatible setuptools and wheel in your environment, then run the install with the no-build-isolation option so pip uses them. This is a workaround, so check for a fixed release too.
Should I downgrade Python to fix this error?
Usually not. Changing the Python version is a bigger step than needed. Installing a compatible setuptools, or updating the code and packages that import pkg_resources, fixes the problem and keeps your Python version current.
Conclusion
The error ModuleNotFoundError: no module named ‘pkg_resources’ appears because setuptools 82 and later no longer include the module. Pin setuptools below 82 for a quick fix, then update the packages or code that import it. Replacing old imports with importlib.metadata and importlib.resources removes the problem for good.

Lois Snyder is a versatile writer with experience across multiple domains. She crafts engaging and informative content, delivering valuable insights and captivating readers with her expertise and passion for diverse topics.
1 thought on “ModuleNotFoundError: No Module Named ‘pkg_resources’ Fix”