Skip to content

Commit

Permalink
fix for importing pxr.Tf on windows anaconda 3.8+ interpreters
Browse files Browse the repository at this point in the history
cpython changed the way the dlls are loaded on windows for python-3.8+.
USD implemented a workaround for this change, installed into
pxr.__init__ (and Tf.__init__).  However, anaconda python interpreters
were patched to behave more like pre-3.8:

   https://github.com/conda-forge/python-feedstock/blob/8195ba1178041b7461238e8c5680eee62f5ea9d0/recipe/patches/0020-Add-CondaEcosystemModifyDllSearchPath.patch#L37

So we now check for anaconda interpreters before using the 3.8+ only
fix.

Fixes issue PixarAnimationStudios#1602
  • Loading branch information
pmolodo committed Oct 5, 2021
1 parent 22853b1 commit 9ac848a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,15 @@ platforms to avoid issues with Boost config files (introduced in Boost version
to use Boost specified config files for their USD build, specify
-DBoost_NO_BOOST_CMAKE=OFF when running cmake.

2. Windows and Python 3.8+
2. Windows and Python 3.8+ (non-Anaconda)
Python 3.8 and later on Windows will no longer search PATH for DLL dependencies.
Instead, clients can call `os.add_dll_directory(p)` to set paths to search.
By default on that platform USD will iterate over PATH and add all paths using
`os.add_dll_directory()` when importing Python modules. Users may override
this by setting the environment variable `PXR_USD_WINDOWS_DLL_PATH` to a PATH-like
string. If this is set, USD will use these paths instead.

Note that the above does not apply to Anaconda python 3.8+ interpreters, as they
are modified to behave like pre-3.8 python interpreters, and so continue to use
the PATH for DLL dependencies. When running under Anaconda users should
configure their system the same way they did for pre-python 3.8.
11 changes: 9 additions & 2 deletions build_scripts/pypi/package_files/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ def windows():
dllPath = os.path.split(os.path.realpath(__file__))[0]
if sys.version_info >= (3, 8, 0):
os.environ['PXR_USD_WINDOWS_DLL_PATH'] = dllPath
else:
os.environ['PATH'] = dllPath + os.pathsep + os.environ['PATH']
# Note that we ALWAYS modify the PATH, even for python-3.8+. This is because:
# - Anaconda python interpreters are modified to use the old, pre-3.8, PATH-
# based method of loading dlls
# - extra calls to os.add_dll_directory won't hurt these anaconda
# interpreters
# - similarly, adding the extra PATH entry shouldn't hurt standard python
# interpreters
# - there's no canonical/bulletproof way to check for an anaconda interpreter
os.environ['PATH'] = dllPath + os.pathsep + os.environ['PATH']
''')

# Get the readme text
Expand Down

0 comments on commit 9ac848a

Please sign in to comment.