From c1749600cd3f900876f87add0a71ca47e84296a7 Mon Sep 17 00:00:00 2001 From: JGamache-autodesk <56274617+JGamache-autodesk@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:17:43 -0500 Subject: [PATCH] Adjust Windows DLL search path for Python 3.8+ (#1440) Fixes #1439 Required by python/cpython#80266 --- python/MaterialX/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/python/MaterialX/__init__.py b/python/MaterialX/__init__.py index bd3999fe36..609e42eae6 100644 --- a/python/MaterialX/__init__.py +++ b/python/MaterialX/__init__.py @@ -1,3 +1,24 @@ +# Python 3.8+ on Windows: DLL search paths for dependent +# shared libraries +# Refs.: +# - https://github.com/python/cpython/issues/80266 +# - https://docs.python.org/3.8/library/os.html#os.add_dll_directory +import os +import sys +if sys.platform == "win32" and sys.version_info >= (3, 8): + import importlib.metadata + try: + importlib.metadata.version('MaterialX') + except importlib.metadata.PackageNotFoundError: + # On a non-pip installation, this file is in %INSTALLDIR%\python\MaterialX + # We need to add %INSTALLDIR%\bin to the DLL path. + mxdir = os.path.dirname(__file__) + pydir = os.path.split(mxdir)[0] + installdir = os.path.split(pydir)[0] + bindir = os.path.join(installdir, "bin") + if os.path.exists(bindir): + os.add_dll_directory(bindir) + from .main import * from .colorspace import *