From f7685fcf92f192e7cda3b4d6dbeb4c247c49af29 Mon Sep 17 00:00:00 2001 From: BHAitken Date: Sat, 4 Jul 2026 21:21:07 -0600 Subject: [PATCH] Fix ImportError on Python 3.12+ from removed distutils module distutils was removed from the standard library in Python 3.12. This broke importing pyffi.utils (and everything that depends on it, e.g. pyffi.formats.nif) with: ModuleNotFoundError: No module named 'distutils' BuildDoc is only used by setup.py's Sphinx documentation build command and is never touched during normal (non-packaging) use of the library, so this wraps the import in a try/except and falls back to a plain object base class when distutils isn't available, rather than failing the whole module import. Verified: pyffi.formats.nif.NifFormat imports and parses a real .nif file cleanly on Python 3.12 with this change, with no workarounds needed on the caller's side. --- pyffi/utils/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyffi/utils/__init__.py b/pyffi/utils/__init__.py index 16d4090ce..5f1007dc3 100644 --- a/pyffi/utils/__init__.py +++ b/pyffi/utils/__init__.py @@ -42,7 +42,14 @@ # ***** END LICENSE BLOCK ***** import os -from distutils.cmd import Command +try: + from distutils.cmd import Command +except ImportError: + # distutils was removed from the standard library in Python 3.12. + # BuildDoc below is only used by setup.py's Sphinx doc-build command, + # which isn't relevant to normal (non-packaging) use of pyffi, so we + # fall back to a plain object rather than fail the whole import. + Command = object class BuildDoc(Command): # pragma: no cover