ModuleNotFoundError: No Module Named ‘pkg_resources’ Fix
The error ModuleNotFoundError: no module named ‘pkg_resources’ means Python cannot find a module that used to ship inside setuptools. It usually appears after you create a fresh virtual environment, upgrade setuptools or install an older package that still imports pkg_resources. The fix is almost always one of three things: install setuptools, pin it below version 82, or replace the code that depends on pkg_resources.
This guide explains why the error happens, how to diagnose it in a few minutes, and which fix suits your situation, including pip build failures, Docker images and CI pipelines. It also shows developers how to move their own code away from pkg_resources for good.
What the ModuleNotFoundError: no module named ‘pkg_resources’ error means
pkg_resources is not a standalone package. For many years it was a module bundled inside setuptools, and it provided tools for finding installed packages, reading entry points, loading data files and parsing version requirements. Scripts generated by older packaging tools often began with from pkg_resources import load_entry_point, and many libraries imported it at start-up.
When Python raises the error, it is telling you that the interpreter running your code has no setuptools installation that contains pkg_resources. Either setuptools is missing, or the version you have no longer includes the module.
Why it happens now
Several changes in the Python packaging world have made this error far more common than it used to be.
- Setuptools 82 removed the module. Setuptools v82.0.0, released on 8 February 2026, removed pkg_resources entirely. Any environment that installs setuptools 82 or newer no longer has it, even though setuptools itself is present.
- New virtual environments start empty. Since Python 3.12, environments created with venv no longer pre-install setuptools, so code that quietly relied on it breaks in a clean environment. Some other tools also create bare environments.
- Older packages still import it. Libraries that have not been updated for years may still call pkg_resources at import time or in their setup scripts.
- The wrong interpreter is in use. You may have installed setuptools into one Python and run your code with another, which is common with multiple Python versions, system Python, conda and virtual environments.
- Pip builds in isolation. When pip builds a package from source, it creates a temporary environment and downloads the latest build tools. If the package’s setup script imports pkg_resources, the build fails even though your own environment has a working copy.
The module was discouraged for a long time. It began issuing deprecation warnings in setuptools v67.5.0, and a removal deadline was announced well before the final change. You can read the details in the setuptools release history.
Diagnose the problem in two minutes
Before you change anything, confirm which Python is running and what it contains. Run these commands in the same terminal where the error appears:
python --version
python -m pip --version
python -m pip show setuptools
python -c "import setuptools; print(setuptools.__version__)"
python -c "import pkg_resources; print(pkg_resources.__file__)"
Read the results like this:
- If
pip show setuptoolssays the package is not found, setuptools is missing. Use Fix 1. - If setuptools is version 82.0.0 or higher and the last command fails, the module has been removed. Use Fix 2 or Fix 4.
- If the pip path shown by
python -m pip --versionpoints to a different environment than you expected, activate the correct virtual environment and try again. - If the error appears only during
pip installof a package, jump to Fix 3.
Fix 1: install setuptools into the right environment
If setuptools is missing, install it into the same interpreter that runs your code. Using python -m pip instead of plain pip avoids installing into the wrong Python.
python -m pip install --upgrade pip
python -m pip install "setuptools<82"
The version limit matters. Installing the newest setuptools will not bring pkg_resources back, because the latest releases no longer contain it. Under conda, use conda install "setuptools<82" instead. After installing, repeat the import check from the diagnosis step to confirm that pkg_resources loads.
Fix 2: pin setuptools below 82 when a library still needs pkg_resources
If setuptools is installed but the import still fails, you probably have version 82 or newer. Install a version below 82 to restore the module:
python -m pip install "setuptools<82"
python -c "import pkg_resources; print('pkg_resources is available')"
To stop the problem returning, record the pin in your project files:
# requirements.txt
setuptools<82
Treat this as a bridge, not a permanent solution. You stay on an older setuptools release, so it is worth tracking down which dependency still needs pkg_resources. Running your program with warnings enabled, or searching the traceback for the package name, usually points to it quickly.
Fix 3: repair a pip install that fails with this error
When the error appears while pip is installing a package, the failing code is the package’s own setup script, running inside pip’s temporary build environment. Installing or pinning setuptools in your normal environment does not help, because pip ignores it during isolated builds. There are two common approaches.
Option A: constrain the build environment
Create a constraints file and expose it through the PIP_CONSTRAINT environment variable, which pip also applies to build environments:
echo "setuptools<82" > constraints.txt
PIP_CONSTRAINT=constraints.txt python -m pip install package-name
On Windows PowerShell, set the variable first with $env:PIP_CONSTRAINT="constraints.txt" and then run the install command.
Option B: build without isolation
Install a suitable setuptools yourself, then ask pip to use your environment for the build:
python -m pip install "setuptools<82" wheel
python -m pip install --no-build-isolation package-name
Option B requires that every other build dependency is also installed, so Option A is usually easier.
Fix 4: upgrade or replace the package that imports pkg_resources
The best long-term fix is to run a version of the library that no longer imports pkg_resources. Check whether the package has a newer release and upgrade it:
python -m pip install --upgrade package-name
If the project is abandoned, look for an actively maintained alternative, or ask the maintainers whether a fix is planned. Many maintainers have already switched to the standard library. If you can edit the code yourself, the next section shows how.
Fix 5: Docker images, CI pipelines and shared environments
Problems in automated builds usually appear after a clean rebuild pulls newer package versions. To make them predictable:
- Pin setuptools in your requirements file or lock file, for example
setuptools<82, until your dependencies are updated. - Install setuptools explicitly in Dockerfiles when you use Python 3.12 or newer virtual environments.
- Set PIP_CONSTRAINT in the build step if a dependency compiles from source.
- Cache and lock your dependency versions so that an unrelated release cannot change your build overnight.
- Rebuild from scratch after changing the pin, because a cached layer may still contain the old environment.
For developers: moving your own code away from pkg_resources
If your project imports pkg_resources, plan to replace it. The module’s own maintainers recommend the standard library and the packaging library as replacements. The archived pkg_resources documentation lists the recommended alternatives in full. The table below covers the most common uses.
| Old pkg_resources code | Modern replacement |
|---|---|
pkg_resources.get_distribution("name").version |
from importlib.metadata import version then version("name") |
pkg_resources.iter_entry_points("group") |
from importlib.metadata import entry_points then entry_points(group="group") |
pkg_resources.resource_string(__name__, "data.txt") |
from importlib.resources import files then files("package").joinpath("data.txt").read_bytes() |
pkg_resources.parse_version("1.2.3") |
from packaging.version import Version then Version("1.2.3") |
pkg_resources.Requirement.parse("name>=1.0") |
from packaging.requirements import Requirement |
The entry_points(group=...) form needs Python 3.10 or newer; older versions can use the importlib_metadata backport. Projects that relied on pkg_resources for namespace packages or other egg-era behaviour need more care, and the recommended route there is implicit namespace packages or, as a short-term step, depending on an older setuptools.
Common mistakes to avoid
- Running pip install pkg_resources. There is no separate package that fixes this error. The module belongs to setuptools.
- Installing into a different Python. Always use
python -m pipand check that the virtual environment is active. - Upgrading setuptools to the newest version as a cure. That can cause the error instead of fixing it.
- Using sudo with pip on system Python. It can break operating system tools. Use a virtual environment instead.
- Mixing conda and pip carelessly. Install setuptools with the same tool that manages the environment.
For more practical technology guides, browse the technology section, read our walkthrough on how to apply for a free tablet from the government, or see our look at the Acrobat AI Assistant for PDF chat.
Frequently asked questions
Is pkg_resources a separate package I can install?
No. It was a module inside setuptools. Installing or pinning setuptools is how you get it back, and only versions below 82 still include it. Running pip install pkg_resources will not solve the problem.
Why did this error appear when my code worked yesterday?
A fresh install probably pulled setuptools 82 or newer, or you created a Python 3.12 or newer virtual environment without setuptools. The code did not change, but the environment did. Check the setuptools version and pin it if needed.
Is it safe to pin setuptools below 82?
It works well as a short-term bridge. You stay on an older release, though, so plan to update or replace the dependency that still needs pkg_resources instead of relying on the pin for years.
What replaces pkg_resources in my own code?
Use importlib.metadata for package versions and entry points, importlib.resources for data files, and the packaging library for version and requirement parsing. These are maintained, faster and work without importing setuptools at all.
Why does pip install still fail when setuptools is installed?
Pip builds some packages in a temporary isolated environment that downloads its own build tools, so your installed copy is ignored. Apply a constraint with PIP_CONSTRAINT, or use no build isolation together with a suitable setuptools version.
Will downgrading Python fix the error?
Not reliably. Older Python versions create environments that include setuptools, which can hide the problem, but upgrading setuptools to 82 or later brings the error back. Fixing the environment and the dependency is more dependable.
Conclusion
The pkg_resources error is a packaging change, not a mystery. Check which Python is running, confirm the setuptools version, and then install or pin setuptools below 82, constrain pip’s build environment or upgrade the dependency that needs the module. If you maintain the code, migrate to importlib.metadata, importlib.resources and packaging so the problem cannot return.

Karen Altizer is a seasoned professional with a wealth of experience, skilled at crafting compelling narratives and strategic messages for diverse audiences.
