Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

The pkg_resources warning turned into a missing module in setuptools 82

Your error

UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.3 more lines it can show

Fix it fast

Most common cause, 1 of 4

Your own code imports pkg_resources

Read versions and entry points through importlib.metadata, and package data through importlib.resources.

Fix
# before
# import pkg_resources
# v = pkg_resources.get_distribution("requests").version
# plugins = pkg_resources.iter_entry_points("myapp.plugins")
# path = pkg_resources.resource_filename("myapp", "data/config.json")

from importlib.metadata import version, entry_points
from importlib.resources import files, as_file

v = version("requests")
plugins = entry_points(group="myapp.plugins")   # Python 3.10+
text = files("myapp").joinpath("data/config.json").read_text()
with as_file(files("myapp").joinpath("data/config.json")) as path:
    print(path)   # a real file path, as resource_filename gave
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

pkg_resources is deprecated as an API is printed by setuptools 67.5 to 81 whenever something imports pkg_resources. setuptools 82.0.0 (February 2026) removed the package, so the same import now fails. Move your own calls to importlib.metadata and importlib.resources; for a library or source build that still needs it, keep setuptools<82 in that environment or build constraint.

  • Applies to setuptools 84.2 (no pkg_resources), setuptools 67.5 to 81 (warning), pip 26.3, Python 3.10 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Note the setuptools version, then list which files import pkg_resources: your project, installed packages, or a launcher in the scripts folder. The file the traceback names decides the cause.

Run this first
python -m pip show setuptools | grep Version
grep -rln "pkg_resources" --include=*.py . "$(python -c 'import sysconfig; print(sysconfig.get_path("purelib"))')" | grep -v "/setuptools/"

Then find the line you see in this list and open its fix:

  1. 1Your own code imports pkg_resourcesThe warning or the ModuleNotFoundError points at a line in your repository, such as get_distribution(...).version or iter_entry_points
  2. 2An installed library still imports pkg_resources at run timeThe failing import is in a file under site-packages, and grep finds nothing in your own code
  3. 3pip builds an old source package whose setup.py imports pkg_resourcesThe ModuleNotFoundError appears while pip is building a package from an sdist, not while your program runs
  4. 4An old launcher script loads the tool through pkg_resourcesThe traceback starts in a command file such as bin/pip, at the line from pkg_resources import load_entry_point, and says the 'pip==...' distribution was not found

What does the error look like?

  • UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  • DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  • ModuleNotFoundError: No module named 'pkg_resources'
  • pkg_resources.DistributionNotFound: The 'pip==20.2.3' distribution was not found and is required by the application

Cause 1 of 4

Your own code imports pkg_resources

You seeThe warning or the ModuleNotFoundError points at a line in your repository, such as get_distribution(...).version or iter_entry_points

Check

Importing pkg_resources from your own module is what prints the deprecation text on setuptools 67.5 to 81. setuptools 82.0.0 deleted the package, and the Python docs now describe it as removed, with importlib.metadata and importlib.resources as the replacements.

Check
grep -rnE "pkg_resources|get_distribution|iter_entry_points|resource_filename" --include=*.py .

Fix

Read versions and entry points through importlib.metadata, and package data through importlib.resources. Both ship with Python, so nothing extra goes into requirements.

Fix
# before
# import pkg_resources
# v = pkg_resources.get_distribution("requests").version
# plugins = pkg_resources.iter_entry_points("myapp.plugins")
# path = pkg_resources.resource_filename("myapp", "data/config.json")

from importlib.metadata import version, entry_points
from importlib.resources import files, as_file

v = version("requests")
plugins = entry_points(group="myapp.plugins")   # Python 3.10+
text = files("myapp").joinpath("data/config.json").read_text()
with as_file(files("myapp").joinpath("data/config.json")) as path:
    print(path)   # a real file path, as resource_filename gave

Verify

The module imports with setuptools 82 or newer installed and prints no pkg_resources warning.

Verify
python -c "import myapp"

Confirmed by docs.python.org

Did this fix it?

Cause 2 of 4

An installed library still imports pkg_resources at run time

You seeThe failing import is in a file under site-packages, and grep finds nothing in your own code

Check

Removing pkg_resources broke every package that still loads it while running. The setuptools 82.0.0 changelog tells environments that rely on it to depend on older setuptools.

Check
python -m pip show setuptools

Fix

First upgrade the library that the traceback names, since a newer release may have dropped the import. If its newest release still imports pkg_resources, hold setuptools below 82 in that environment and record the pin so it is removed later.

Fix
python -m pip install --upgrade <library-from-the-traceback>
# if it still fails:
python -m pip install "setuptools<82"

Verify

The program starts, and pip show setuptools reports 81.x or lower only where you meant to pin it.

Verify
python -c "import pkg_resources" && python -m pip show setuptools | grep Version

Confirmed by setuptools.pypa.io

Did this fix it?

Cause 3 of 4

pip builds an old source package whose setup.py imports pkg_resources

You seeThe ModuleNotFoundError appears while pip is building a package from an sdist, not while your program runs

Check

pip builds sdists in an isolated environment and installs the newest setuptools there unless told otherwise, so a setup.py that imports pkg_resources fails since February 2026. Since pip 26.2, normal constraints files and PIP_CONSTRAINT no longer reach that build environment.

Check
python -m pip --version

Fix

Pass a build constraint that caps setuptools for the build step only. --build-constraint exists from pip 25.3, and PIP_BUILD_CONSTRAINT does the same through the environment, which suits CI.

Fix
echo "setuptools<82" > build-constraints.txt
python -m pip install --build-constraint build-constraints.txt <old-package>
# or in CI:
export PIP_BUILD_CONSTRAINT=build-constraints.txt

Verify

The install log shows the package built and installed, with no pkg_resources import error.

Verify
python -m pip show <old-package>

Confirmed by pip.pypa.io

Did this fix it?

Cause 4 of 4

An old launcher script loads the tool through pkg_resources

You seeThe traceback starts in a command file such as bin/pip, at the line from pkg_resources import load_entry_point, and says the 'pip==...' distribution was not found

Check

Launchers written by older installers pin the exact version they were made for and resolve it through pkg_resources. After pip upgrades itself into a different location, that version is gone and the launcher raises DistributionNotFound; with setuptools 82 it fails earlier, on the import.

Check
head -8 "$(command -v pip3)"

Fix

Run pip through the interpreter, which never reads the stale launcher. Reinstalling a tool with current pip writes a new launcher that imports the entry function directly, with no pkg_resources line.

Fix
python3 -m pip --version
python3 -m pip install --force-reinstall --no-deps <tool-name>

Verify

python3 -m pip --version prints the upgraded pip, and the rewritten launcher's first lines no longer mention pkg_resources.

Verify
head -8 "$(command -v <tool-name>)"

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Add a CI step that fails when grep finds pkg_resources in your source tree, so the import cannot creep back in.
  • Keep a build-constraints.txt in the repo for any sdist-only dependency, and pass it with --build-constraint in every install step.
  • Invoke tools as python -m pip and python -m <tool> in scripts and Dockerfiles, so a stale launcher never runs.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.