Skip to content

Fix ImportError on Python 3.12+ from removed distutils module#85

Open
BHAitken wants to merge 1 commit into
niftools:developfrom
BHAitken:fix/python312-distutils-import
Open

Fix ImportError on Python 3.12+ from removed distutils module#85
BHAitken wants to merge 1 commit into
niftools:developfrom
BHAitken:fix/python312-distutils-import

Conversation

@BHAitken

@BHAitken BHAitken commented Jul 5, 2026

Copy link
Copy Markdown

Summary

distutils was removed from the Python standard library in 3.12, which breaks 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 — parsing a NIF/KFM/etc file never needs it. 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 for every user on 3.12+.

Test plan

  • Verified pyffi.formats.nif.NifFormat imports cleanly on Python 3.12 with this change (previously failed at import time)
  • Verified it parses a real Skyrim .nif file end-to-end afterward (reads header, walks the full block tree, extracts extra-data values) with no workarounds needed on the caller's side
  • Confirmed distutils is the only remaining Python-3.12-incompatible stdlib reference in the codebase (the time.clock() issue in object_models/xml/__init__.py is already fixed on develop, just not yet released to PyPI)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant