nnictl: No module named 'pkg_resources' (NNI fix)
NNI 3.0 (the last release; the repo is archived) does import pkg_resources in nni/tools/nnictl/nnictl.py, so nnictl fails with ModuleNotFoundError: No module named 'pkg_resources' on setuptools 82+. Tested fix: pip install "setuptools<81".
1. The error: nnictl from nni 3.0 with setuptools 84
pip install nni gives 3.0 (2023-09-15), the last release. Microsoft has archived the GitHub repository (last push 2024-07-03), so no fix is coming. nni does not depend on setuptools, so it uses whatever the venv has. In a Python 3.11 venv with setuptools 84.2.1, every nnictl command fails:
$ nnictl --version
Traceback (most recent call last):
File "/path/to/venv/bin/nnictl", line 4, in <module>
from nni.tools.nnictl.nnictl import parse_args
File "nni/tools/nnictl/nnictl.py", line 7, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
nni/tools/nnictl/nnictl.py line 7 is a plain import pkg_resources (used to print the version), and setuptools 82.0.0 removed pkg_resources. A venv with no setuptools at all (uv venv, or python -m venv on Python 3.12+) fails the same way. So nnictl create --config config.yml never gets as far as reading your config.
2. Fix: pin setuptools below 81 (tested)
$ pip install "setuptools<81" # gave 80.10.2
$ nnictl --version
nni/tools/nnictl/nnictl.py:7: 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
3.0
$ nnictl experiment list
nni/tools/nnictl/nnictl.py:7: 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
INFO: Cannot find experiments.
Both commands ran. "Cannot find experiments." is the normal answer in a fresh environment (it exits with code 1). The pkg_resources is deprecated warning is harmless; set PYTHONWARNINGS="ignore:pkg_resources is deprecated as an API" to hide it. We did not run a full experiment, which also needs your trial code and its framework.
3. The Python API imports fine
Only the nnictl tool (and the trial tools under nni/tools/trial_tool/, which also import pkg_resources) is affected. On setuptools 84.2.1, this worked:
$ cat b4.py
import nni
from nni.experiment import Experiment
print(nni.__version__, Experiment.__name__)
$ python b4.py
3.0 Experiment
We checked imports only, not Experiment.run(). Keeping the setuptools pin is the safe choice for any environment that runs nni.
Related: No module named 'pkg_resources' (general fix) · openmim (same cause) · TensorBoard.
Frequently asked questions
Will NNI release a fix?
Unlikely. Microsoft has archived the NNI GitHub repository (last push 2024-07-03), and 3.0 is the last release on PyPI.
Does import nni fail too?
No. In our test import nni and from nni.experiment import Experiment worked on setuptools 84.2.1; only nnictl and the trial tools import pkg_resources.
Written with AI assistance. Measured on 2026-10-24 on Linux with nni 3.0, numpy 2.4.6, CPython 3.11.17, setuptools 80.10.2 and 84.2.1. Output pasted unedited except shortened paths. PlainTables is our extension; NNI is free.