ModuleNotFoundError: No Module Named ‘pkg_resources’ Fix

If you have just seen ModuleNotFoundError: no module named ‘pkg_resources’ in your terminal, you are dealing with one of the most common Python packaging problems. It usually appears when you install a package, start an older project or run a script, and it stops everything with a traceback that points at an import line you never wrote.

The good news is that the cause is narrow and the fix is quick once you know which situation you are in. This guide explains what pkg_resources is, why it has gone missing, and the exact commands that solve the error in virtual environments, pip builds, Docker images and continuous integration. It also shows how to remove the dependency from your own code for good.

What pkg_resources is and why the error appears

The pkg_resources module has always shipped inside setuptools, the long-standing Python packaging library. Older projects used it to look up installed package versions, read entry points, find data files and declare namespace packages. Because it lived inside setuptools, any code containing import pkg_resources quietly depended on setuptools being present, even when nobody listed it as a requirement.

The error message simply means Python searched every folder on its import path and found no module with that name. It is not a sign of a corrupted installation, and it rarely points to a problem with your operating system. Something about the environment changed, and a module that used to be there is gone.

The two main causes

Cause one: setuptools is not installed in the environment

From Python 3.12 onward, new virtual environments are created without setuptools. Before that, a fresh environment came with it, so many old scripts and build files worked without anyone declaring the dependency. If you created a new environment with a recent Python and then ran a project that imports pkg_resources, Python has nothing to import. Docker images based on newer Python versions can behave the same way, which is why a build that worked last year may fail after a base image update.

Cause two: setuptools is installed but too new

This is the cause that catches people out in 2026. Setuptools 82.0.0 removed pkg_resources entirely in February 2026, after years of deprecation warnings. Any environment that upgraded to setuptools 82 or later no longer contains the module, and later releases do not bring it back. That means the old advice of simply running pip install setuptools can fail to help. Pip installs the newest version, and the newest version is exactly the one without pkg_resources.

How to tell which situation you are in

A few clues usually make the cause obvious before you change anything:

  • The error appears in a brand new virtual environment: setuptools was never installed.
  • The error appears right after you upgraded packages: setuptools 82 or later removed the module.
  • The error appears during pip install, under a line about getting requirements to build a wheel: the package’s build script imports pkg_resources inside pip’s temporary build environment.
  • The error appears only in Docker or CI: a base image or build tool changed underneath you.

How to fix the error step by step

Step 1: check which Python you are really using

Many people install a package with one interpreter and run code with another. Before changing anything, confirm which interpreter and which pip you are using:

python -c "import sys; print(sys.executable)"
python -m pip --version

Both commands should point inside the virtual environment you expect. Always use python -m pip rather than a bare pip command, because it guarantees the package is installed for the interpreter you just checked.

Step 2: see whether setuptools is present and which version it is

python -m pip show setuptools

If pip says the package is not found, setuptools is missing. If it shows version 82 or higher, pkg_resources is missing because the module was removed. Either way, the next step is the same.

Step 3: install a setuptools release that still includes pkg_resources

python -m pip install "setuptools<82"

The quotation marks matter, especially on Windows and in shells such as zsh, because the less-than sign is otherwise read as a redirect. Setuptools 81 and the 80 series still ship pkg_resources, so any of them solves the immediate error. Some teams pin an exact version such as 80.10.2 so that builds stay identical from one day to the next.

Step 4: test the import

python -c "import pkg_resources; print('pkg_resources is available')"

You may see a deprecation warning when the module loads. That warning is expected on supported versions, and it is a reminder to migrate away in the longer term, which is covered below.

Fixing the error during pip install

Sometimes the traceback appears while installing a package, with a message that getting requirements to build the wheel did not run successfully. This happens because pip builds many packages inside a temporary isolated environment, and that environment downloads the newest setuptools by default. If the package’s setup file still imports pkg_resources, the build fails even though your own environment is perfectly fine.

You have three practical options:

  1. Install a newer release of the package, because many maintainers have already removed the import.
  2. Install the build tools yourself, then tell pip to use them: run pip install "setuptools<82" wheel, followed by pip install --no-build-isolation your-package.
  3. If the package is abandoned, fork it or replace it with a maintained alternative.

The first option is the healthiest. A package that still depends on pkg_resources is carrying a problem that will keep returning, so a newer release saves you from repeating this fix on every new machine.

Fixing it in Docker and continuous integration

Container builds and CI pipelines are where this error strikes without warning. Your code did not change, but an unpinned build tool did, and the next build fails. Treat setuptools like any other dependency and pin it deliberately.

  • Add setuptools<82 to your requirements or constraints file if your project still needs pkg_resources.
  • In a Dockerfile, install the pinned version before the rest of your dependencies so the layer is cached predictably.
  • Rebuild without the cache once, so an old layer containing a newer setuptools cannot linger.
  • Pin the Python base image to a specific version, so a quiet base image update does not change what is installed.

If the error appears on a server you rent rather than on your own machine, it is worth reading why technical support matters when choosing a hosting provider, because a responsive host can help you rebuild a broken Python environment quickly.

The permanent fix: stop using pkg_resources

Pinning is a bridge, not a destination. Because pkg_resources has been removed upstream, code that depends on it will eventually be stuck on old tooling. The standard library now covers the common uses, and the importlib.metadata documentation explains how it replaces the entry point and metadata features that pkg_resources used to provide, working alongside importlib.resources for data files.

Old pkg_resources code Modern replacement
pkg_resources.get_distribution("name").version importlib.metadata.version("name")
pkg_resources.iter_entry_points("group") importlib.metadata.entry_points(group="group")
pkg_resources.resource_filename("pkg", "file") importlib.resources.files("pkg") / "file"
pkg_resources.declare_namespace(__name__) Remove it and use implicit namespace packages

Reading a package version is the most common case, and the new version is shorter than the old one:

from importlib.metadata import version

print(version("requests"))

The files function in importlib.resources needs Python 3.9 or newer, which covers every Python release still receiving security fixes. If your project supports older interpreters, you can use the importlib_metadata and importlib_resources backports from PyPI instead.

Finding the code that needs changing

Search your project folder for the text pkg_resources and review every match. If the only matches are inside third-party packages, update those packages instead. If you maintain the code, replace each call using the table above, run your tests, and then remove the setuptools pin you added as a temporary fix.

Common mistakes to avoid

  • Installing setuptools with one Python and running your code with another.
  • Running pip install --upgrade setuptools and expecting it to restore a module that newer releases no longer include.
  • Forgetting the quotation marks around setuptools<82, which makes the shell treat the symbol as a redirect.
  • Leaving the pin in place forever instead of planning a migration.
  • Skipping the traceback. The file path on the last lines names the package that imports pkg_resources, and that package is the real target of your fix.

More practical troubleshooting guides are collected in our technology section, and developers who install packages from behind a filtered network may also find our guide on where to buy a proxy server useful.

Frequently asked questions

What does ModuleNotFoundError: no module named ‘pkg_resources’ mean?

It means Python tried to import pkg_resources and could not find it in the active environment. The module belongs to setuptools, so the usual reasons are that setuptools is not installed, or that the installed version is new enough to have removed the module.

Is pkg_resources part of Python itself?

No. It is not part of the Python standard library. It is a module inside setuptools, which you install separately with pip. That is why a clean environment can lack it, even though Python itself runs perfectly well.

Why does pip install setuptools no longer fix the error?

Pip installs the latest setuptools, and since version 82.0.0 the latest releases no longer include pkg_resources. Install a version below 82 instead, using the quoted command shown in this guide, and then test the import again.

Which setuptools version should I pin?

Any release below version 82 still contains pkg_resources. Many teams choose the newest 80 or 81 release that works with their project, while others pin an exact version such as 80.10.2 so that every build installs the same tools.

Can I ignore the deprecation warning?

Short term, yes, because the warning does not stop your code from running on supported setuptools versions. Long term, no. Upstream has removed the module, so code that relies on it will keep needing a pin. Plan a migration to importlib.metadata and importlib.resources.

How do I find which package imports pkg_resources?

Read the traceback from the bottom upward. The file path on the last import line names the package that is at fault. You can also search your own project folder for the text import pkg_resources to find code you control and update it.

Conclusion

The ModuleNotFoundError about pkg_resources almost always means setuptools is missing or too new. Check your interpreter, install setuptools below version 82 for a quick fix, and use no build isolation for stubborn packages. Then plan to replace pkg_resources with importlib.metadata and importlib.resources so your project keeps working as tools continue to change.

Leave a Comment