Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Windows DLL search path for Python 3.8+ #1440

Merged
21 changes: 21 additions & 0 deletions python/MaterialX/__init__.py
Original file line number Diff line number Diff line change
@@ -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):
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
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]
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
bindir = os.path.join(installdir, "bin")
if os.path.exists(bindir):
os.add_dll_directory(bindir)

from .main import *
from .colorspace import *

Expand Down