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 showFix it fast
Most common cause, 1 of 4Your own code imports pkg_resources
Read versions and entry points through importlib.metadata, and package data through importlib.resources.
# 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 gaveShort 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.
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.
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:
- 1Your own code imports pkg_resources
The warning or the ModuleNotFoundError points at a line in your repository, such as get_distribution(...).version or iter_entry_points - 2An installed library still imports pkg_resources at run time
The failing import is in a file under site-packages, and grep finds nothing in your own code - 3pip builds an old source package whose setup.py imports pkg_resources
The ModuleNotFoundError appears while pip is building a package from an sdist, not while your program runs - 4An old launcher script loads the tool through pkg_resources
The 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.htmlModuleNotFoundError: 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.
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.
# 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 gaveVerify
The module imports with setuptools 82 or newer installed and prints no pkg_resources warning.
python -c "import myapp"Confirmed by docs.python.org
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.
python -m pip show setuptoolsFix
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.
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.
python -c "import pkg_resources" && python -m pip show setuptools | grep VersionConfirmed by setuptools.pypa.io
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.
python -m pip --versionFix
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.
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.txtVerify
The install log shows the package built and installed, with no pkg_resources import error.
python -m pip show <old-package>Confirmed by pip.pypa.io
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.
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.
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.
head -8 "$(command -v <tool-name>)"Confirmed by github.com
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.