No module named distutils 🐍 Python

ModuleNotFoundError: No module named 'distutils'

Python 3.12 removed distutils; old packages or tools that import it fail.

Seen on: Python

Meaning

distutils was deprecated in 3.10 and removed in 3.12. Old versions of numpy, node-gyp, virtualenv and setup.py scripts still import it.

Common causes

  • Running old packages on Python 3.12+
  • Old setup.py-based builds
  • node-gyp using system Python 3.12

⚡ Quick fix

  1. Install setuptools (provides a distutils shim): pip install setuptools
  2. Upgrade the failing package
  3. Use Python 3.11 for legacy projects

Detailed fix by platform

Python

  1. python -m pip install -U setuptools

How to diagnose

  1. Version — python --version
  2. Package — Which package imports distutils?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.