The error, verbatim
Jump to the fix ↓Traceback (most recent call last):
File "<string>", line 1, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
Tested on
- Python
- 3.14.5 and 3.10.11
- setuptools
- 80.10.2, 81.0.0, 82.0.0, 84.2.0
- Installers
- pip 26.2.1, uv 0.13.3
- Re-run
- November 3: Python 3.14.9, setuptools up to 84.2.1, pip 26.2.2, uv 0.13.7, TensorBoard 2.21.0 (Linux)
- OS
- Windows 11 Pro; Ubuntu on GitHub Actions
✓ Last re-run on GitHub Actions · see the run · all repros
Contents
pkg_resources was never part of Python. It came with setuptools, and two separate changes took it away:
- Python 3.12 stopped putting setuptools into new virtual environments. A fresh 3.14 venv had only
pipin it, andimport pkg_resourcesfailed right away. Auv venvdidn’t have setuptools either. - setuptools removed
pkg_resourcesin version 82.0.0 (February 2026). So the answer you’ll find everywhere, “install setuptools”, now installs a setuptools without it.
I checked each version in the same venv:
| setuptools | import pkg_resources |
|---|---|
| none (fresh 3.14 venv) | No module named 'pkg_resources' |
| 80.10.2 | works, with a deprecation warning |
| 81.0.0 | works, with the same warning |
| 82.0.0 | No module named 'pkg_resources' |
84.2.0 (latest, what pip install setuptools gives you) |
No module named 'pkg_resources' |
The warning on 80 and 81 says pin to Setuptools<81, but 81.0.0 still had the module. The cut is at 82.
Where the import comes from decides the fix. It’s usually one of three places: your own code, a package you installed, or a package being built from source during pip install.
A package you use imports it
First, try upgrading that package. Newer releases often no longer import it.
TensorBoard is a common case. 2.15.2 imports pkg_resources in tensorboard/default.py, and with setuptools 84.2.0, tensorboard --version failed with this error. Upgrading fixed it:
pip install -U tensorboardIf you can’t upgrade the package, pin setuptools below 82 in the same environment:
pip install "setuptools<82"pip install fails while building a package
If the error shows up during pip install, under Getting requirements to build wheel, the package’s own setup.py imports pkg_resources. I reproduced it with a small package:
error: subprocess-exited-with-error
ModuleNotFoundError: No module named 'pkg_resources'
ERROR: Failed to build 'file:///D:/nk-pkgres/oldpkg' when getting requirements to build wheel
pip builds the package in a separate, temporary environment with the latest setuptools, so installing an older setuptools in your own environment doesn’t change anything.
Tell pip which setuptools to use for the build:
echo "setuptools<82" > build-constraints.txt
pip install --build-constraint build-constraints.txt your-packageWith uv, the flag is the same:
uv pip install --build-constraint build-constraints.txt your-packageAnother option: install "setuptools<82" and wheel into your environment, then run pip install --no-build-isolation your-package. That worked too, but it builds with whatever happens to be installed in your environment.
Your own code imports it
Replace it with the standard library. The most common use, reading an installed package’s version:
import importlib.metadata
importlib.metadata.version("pip")For resource files and entry points, the setuptools page on pkg_resources points to importlib.resources and importlib.metadata. Until you’ve moved over, "setuptools<82" in your requirements keeps the old code running.
uv environments
uv venv creates an environment without setuptools, so anything that imports pkg_resources fails there first. Adding setuptools with uv pip install setuptools gave 84.2.0, which still failed.
uv pip install "setuptools<82"Where and how I checked it
Windows 11 Pro, Python 3.14.5 and 3.10.11, October 20, 2026. Fresh venvs from py -m venv and uv venv (uv 0.13.3), with setuptools 80.10.2, 81.0.0, 82.0.0 and 84.2.0. A one-file package whose setup.py imports pkg_resources was installed with pip 26.2.1 and uv, with and without build constraints. TensorBoard 2.15.2 and 2.21.0 ran on Python 3.10. Every message above is the real output.
Re-checked on November 3, 2026 on Linux (GitHub Actions ubuntu-latest, Python 3.14.9), with a fresh venv for every setuptools version. 80.10.2 and 81.0.0 still imported pkg_resources with a deprecation warning; 82.0.0, 83.0.0 and 84.2.1 had no pkg_resources folder and failed. TensorBoard 2.15.2 failed with the latest setuptools and hit the NumPy AttributeError with setuptools<82, while TensorBoard 2.21.0 ran with setuptools 84.2.1. The setup.py package failed in pip 26.2.2 and uv 0.13.7 until --build-constraint was added, PIP_CONSTRAINT still didn’t reach the build, and importlib.metadata worked with no setuptools at all. The script and the run are public.
— N.K., end of entry No.082