TensorBoard: No module named 'pkg_resources' (tested fix)
tensorboard fails with ModuleNotFoundError: No module named 'pkg_resources' because tensorboard 2.20.0 and older import it, and setuptools 82+ no longer ships it. Fix: pip install -U "tensorboard>=2.21", or pip install "setuptools<81". Tested below; your event files are not affected.
1. Fresh install: tensorboard 2.20.0 fails to start
pip install tensorboard==2.20.0 in a fresh Python 3.11 venv pulled setuptools 84.2.1 and numpy 2.4.6. tensorboard declares setuptools>=41.0.0, so the newest setuptools gets installed, and setuptools 82.0.0 removed pkg_resources:
$ tensorboard --version
Traceback (most recent call last):
File "bin/tensorboard", line 4, in <module>
from tensorboard.main import run_main
File "site-packages/tensorboard/main.py", line 27, in <module>
from tensorboard import default
File "site-packages/tensorboard/default.py", line 30, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
tensorboard/default.py line 30 runs import pkg_resources (so does tensorboard/data/server_ingester.py). 2.19.0 failed the same way. Running pip install setuptools does not help, because the newest setuptools is exactly the version without pkg_resources.
2. Your training script still logs fine
Only the tensorboard viewer breaks. PyTorch's SummaryWriter writes event files without touching pkg_resources. With tensorboard 2.20.0 + setuptools 84.2.1 (torch 2.14.1+cpu, Python 3.13):
import torch
from torch.utils.tensorboard import SummaryWriter
print("torch", torch.__version__)
w = SummaryWriter("runs/demo")
for step in range(3):
w.add_scalar("loss", 1.0 / (step + 1), step)
w.close()
print("wrote", "runs/demo")
torch 2.14.1+cpu
wrote runs/demo
So the logs you already have are fine. Once the viewer works, tensorboard --logdir runs finds them (--inspect listed the scalars tag in runs/demo on 2.20.0 with the fix below and on 2.21.0).
3. Fix A: upgrade to tensorboard 2.21.0
pip install -U "tensorboard>=2.21"
$ tensorboard --version
TensorFlow installation not found - running with reduced feature set.
2.21.0
2.21.0 starts with setuptools 84.2.1 and numpy 2.4.6. ("TensorFlow installation not found" is a normal notice when TensorFlow is not installed, not an error.) If TensorFlow is pinned in your project, check that its own tensorboard pin allows 2.21.
4. Fix B: keep your tensorboard, pin setuptools<81
pip install "setuptools<81"
That installed setuptools 80.10.2, and 2.20.0 starts with a deprecation warning:
$ tensorboard --version
site-packages/tensorboard/default.py:30: 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.
import pkg_resources
TensorFlow installation not found - running with reduced feature set.
2.20.0
setuptools 81.0.0 also still had pkg_resources, but <81 is the pin the warning itself recommends.
5. tensorboard 2.16 and older: np.string_ next
On older tensorboard, pinning setuptools only gets you to the next error. tensorboard 2.15.2 with setuptools 80.10.2 and numpy 2.4.6:
$ tensorboard --version
site-packages/tensorboard/default.py:30: 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.
[... traceback trimmed ...]
^^^^^^^^^^
File "site-packages/numpy/__init__.py", line 778, in __getattr__
raise AttributeError(
AttributeError: `np.string_` was removed in the NumPy 2.0 release. Use `np.bytes_` instead.
The traceback runs through tensorboard/plugins/hparams/metadata.py into compat/tensorflow_stub/dtypes.py. 2.16.2 failed the same way, and 2.17.1 started fine on numpy 2.4.6. For 2.16 and older, either upgrade tensorboard (fix A) or pin both "setuptools<81" "numpy<2". More on that error: NumPy 2 breaking changes.
Same pkg_resources error in other packages: No module named 'pkg_resources' (general fix) ยท librosa.
Frequently asked questions
Why does pip install setuptools not fix it?
The newest setuptools (82.0.0 and later) no longer contains pkg_resources. You need setuptools<81, or a tensorboard that does not import it (2.21.0).
Which tensorboard version fixes the pkg_resources error?
tensorboard 2.21.0 started with setuptools 84.2.1 in our test; 2.19.0 and 2.20.0 failed.
Written with AI assistance. Measured on 2026-10-24 on Linux in fresh uv venvs (Python 3.11.17): tensorboard 2.15.2, 2.16.2, 2.17.1, 2.19.0, 2.20.0 and 2.21.0 with setuptools 84.2.1 or 80.10.2 and numpy 2.4.6; SummaryWriter on Python 3.13.5 with torch 2.14.1+cpu. Output pasted unedited except shortened paths and marked trims. PlainTables is our extension; TensorBoard is free.