OpenUSD icon indicating copy to clipboard operation
OpenUSD copied to clipboard

Unable to Import Precompiled Python37+USD Binaries (Windows)

Open mgbvox opened this issue 9 months ago • 2 comments

On Windows 10, working in an offline/high-security environment (no internet, no exceptions). We use Python 3.7.

I was able to get the precompiled binaries provided by NVIDIA here: https://developer.nvidia.com/downloads/usdusdbinaries2211usdpy37windows-8664release02211zip

These I've extracted to c:/USD.

The contents of that dir look like:

(3.7.9) PS C:\me> ls c:/USD                                                                                                                                                                                                                                                  
d-----          5/3/2024   2:40 PM                bin                                                                                                                                                                                                                                                              
d-----        11/13/2023   3:26 PM                build                                                                                                                                                                                                                                                            
d-----        12/14/2022   4:54 PM                BUILD_INFO                                                                                                                                                                                                                                                       
d-----          6/2/2022  11:28 AM                build_scripts                                                                                                                                                                                                                                                    
d-----          5/3/2024   2:40 PM                cmake                                                                                                                                                                                                                                                            
d-----        12/14/2022   4:54 PM                doc                                                                                                                                                                                                                                                              
d-----          6/2/2022  11:28 AM                docs          
... and lots, lots more!

I can see that the pxr library is exposed under:

(3.7.9) PS C:\me> ls C:\USD\lib\python\
d-----        12/14/2022   4:55 PM                pxr

So I should be able to add this to path and import, right?

import sys

pxr = "C:/USD/lib/python"
sys.path.append(pxr)
import pxr
print(pxr.__file__) # works
from pxr import Ar # uh oh!
print(Ar.__file__)

Alas, this raises the following error:

C:\venvs\3.7.9\Scripts\python.exe C:\me\resolverImport.py 
C:/USD/lib/python\pxr\__init__.py
Traceback (most recent call last):
  File "C:\me\resolverImport.py", line 7, in <module>
    from pxr import Ar
  File "C:/USD/lib/python\pxr\Ar\__init__.py", line 24, in <module>
    from pxr import Tf
  File "C:/USD/lib/python\pxr\Tf\__init__.py", line 163, in <module>
    PreparePythonModule()
  File "C:/USD/lib/python\pxr\Tf\__init__.py", line 89, in PreparePythonModule
    "." + moduleName, f_locals["__name__"])
  File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.

Process finished with exit code 1

When I grab the usd-core library (v 23.11) from pypi (manually, since we're offline), and point sys.path at that, no problem! I place the usd-core lib under this dir: c:/me/optional/usd-core

And my script:

import sys

pxr = "c:/me/optional/usd-core"
sys.path.append(pxr)
import pxr
print(pxr.__file__)
from pxr import Ar # works!
print(Ar.__file__)

However, the whole point of this is that we're trying to build a custom Asset Resolver that works in standalone python, and as such need to compile against libraries not present in USD-CORE. Hence my attempts to use the pxr lib distributed in those binaries.

plz halp.

mgbvox avatar May 03 '24 18:05 mgbvox

Hi @mgbvox. When you build USD for yourself, the build script reminds you to to set PYTHONPATH and PATH. We also included that in the README for the prebuilt binaries, but it unfortunately got clobbered for that version. This should be fixed in the prebuilt binaries for newer USD releases going forward. In any case, environment setup instructions that you need are here: https://openusd.org/release/tut_usd_tutorials.html#environment-setup

mati-nvidia avatar May 03 '24 20:05 mati-nvidia

Filed as internal issue #USD-9632

jesschimein avatar May 06 '24 17:05 jesschimein

@mati-nvidia @jesschimein Should we close this issue?

nvmkuruc avatar Sep 04 '24 22:09 nvmkuruc

Closing for now per mati-nvidia's comments! Feel free to re-open if you're still running into this issue.

jesschimein avatar Sep 04 '24 22:09 jesschimein