Interview Prep/Python for DevOps/Environments, imports & packaging errors

`pkg_resources is deprecated as an API` warnings, or `ModuleNotFoundError: No module named 'pkg_resources'` in a fresh venv.

IntermediateTroubleshootingEnvironments, imports & packaging errors
Answer

Likely causes → Old code or a library uses pkg_resources (part of setuptools), which is deprecated and not installed by default in new venvs on Python 3.12+.

Diagnose →

grep -rn "pkg_resources" src/ .venv/lib/*/site-packages/ | head

Fix → Replace with importlib.metadata.version("pkg") and importlib.resources.files(...). For third-party code, upgrade the library; as a stopgap install setuptools.

Prevent → Run tests with -W error::DeprecationWarning for your own code.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, imports & packaging errors