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

`ModuleNotFoundError: No module named 'distutils'` on Python 3.12.

IntermediateTroubleshootingEnvironments, imports & packaging errors
Answer

Likely causes → distutils was removed from the standard library in Python 3.12 (PEP 632); old packages or scripts still import it.

Diagnose →

python --version
pip install <pkg> -v 2>&1 | grep -i distutils

Fix → Upgrade the offending package (most fixed this long ago). setuptools provides a compatibility shim, so installing a recent setuptools often resolves it. Replace distutils.util.strtobool and similar in your code with small local functions.

Prevent → Test on new Python versions before upgrading base images.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, imports & packaging errors