Distutils has been deprecated since Python-3.10 and was REMOVED in Python-3.12 https://docs.python.org/3.12/library/distutils.html
So you need to replace it with setuptools for instance. It is API compatible and should almost work out of the box.
See the migration guide here: https://peps.python.org/pep-0632/#migration-advice