ImportError: DLL load failed while importing _tf: A dynamic link library (DLL) initialization routine failed

I was building usd on my local machine (Windows 11), I use VSCode. after building, I execute Usdviewq.Launcher().Run() ( basically poping up USDView )
I run this from within VSCode and it all works, run this from command line through python directly, works fine.

I then switched to building the binaries on gitlab using this image mcr.microsoft.com/windows/servercore:ltsc2022-amd64
build works fine.
when I copy the artifacts to my local machine
and run the same code through VSCode, all works fine, when I run it from the command line, directly through python, it fails … this is my callstack:


Traceback (most recent call last):
  File "D:\test\test_usd.py", line 24, in <module>
    import pxr.Usdviewq as Usdviewq
  File "d:\venv-3.9\lib\site-packages\pxr\Usdviewq\__init__.py", line 10, in <module>
    from pxr import Tf
  File "d:\venv-3.9\lib\site-packages\pxr\Tf\__init__.py", line 161, in <module>
    PreparePythonModule()
  File "d:\venv-3.9\lib\site-packages\pxr\Tf\__init__.py", line 86, in PreparePythonModule
    module = importlib.import_module(
  File "d:\python\3.9\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing _tf: A dynamic link library (DLL) initialization routine failed.

Any hint would be greatly appreciated

When it works, can you try printing out PATH and PYTHONPATH

eg

import os
print(os.environ['PATH'])
print(os.environ.get('PYTHONPATH'))

and then do it again with the artifact? My guess is that you’ll have to point PATH and PYTHONPATH into the artifact in a similar way to make it work.

I did get it to work. My PATH variable was huge, and also had a couple weird old folders in there. I cleaned it up and it just works.
I am still confused about what made the process run successfully from VSCode but not from command line but I cannot repro anymore (I tried to programmatically bloat my PATH variable but it didn’t do anything). Anyhow, thanks for answering!