PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.1k stars 1.21k forks source link

Python: ImportError: DLL load failed while importing _usdSchemaExamples #3376

Closed ttrently closed 2 hours ago

ttrently commented 4 hours ago

Description of Issue

Python failing to import the UsdSchemaExamples from a clean build of Usd, this extends to other custom schemas build on that same build.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\Programs\Usd\Build\release\lib\python\pxr\UsdSchemaExamples\__init__.py", line 25, in <module>
    Tf.PreparePythonModule()
  File "E:\Programs\Usd\Build\release\lib\python\pxr\Tf\__init__.py", line 103, in PreparePythonModule
    module = importlib.import_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing _usdSchemaExamples: The specified module could not be found.

Steps to Reproduce

  1. Build latest v24.08 via python build_scripts\build_usd.py E:\Programs\Usd\Build\release
  2. Add Usd paths to environment PATH and PYTHONPATH
  3. Run Python and attempt to import UsdSchemaExamples

System Information (OS, Hardware)

Package Versions

ttrently commented 2 hours ago

This ended up being a Python 3.8+ and Windows issues where DLL's are only loaded from trusted locations (https://docs.python.org/3/whatsnew/3.8.html#ctypes).

Manually adding the Usd plugins directory via os.add_dll_directory allowed me to import UsdSchemaExamples correctly.