ID 600502 - Nuke cannot be imported as a Python module in an external Python installation when using USG_SHIMLIB_PATH

Follow

Problem summary:
Nuke cannot be imported as a Python module in an external Python installation when using USG_SHIMLIB_PATH
 
Customer reported version:
Nuke 16.0v3
 
Customer reported platform:
Windows 10
 
Steps to reproduce:
1) Install Python 3.11.7 (or a different version depending on the Nuke release): https://www.python.org/downloads/release/python-3117/
2) Open a Command Prompt window, and run the following commands:

set PYTHONPATH=C:\Program Files\Nuke16.0v3\lib\site-packages set USG_SHIMLIB_PATH=C:\Program Files\Nuke16.0v3set USG_DEBUG_USDSHIMLIB=1
3) Launch the installed version of Python, and attempt to import nuke
4) Observe how the FnUsdShim DLL cannot be found, despite the USG_SHIMLIB_PATH environment variable being set:
>>> import nuke--Initialize FnUsdShim--  plugin filename='FnUsdShim.0.6.dll'  ...explicit plugin file path(search paths disabled)='C:\Users\NickBeaufait\FnUsdShim.0.6.dll'FnUsdAbstraction message:  FnUsdShim plugin not found at: [FnUsdShim.0.6.dll]. Reason: The system cannot find the file specified.  ...searching ENV VAR paths 'C:\Program Files\Nuke16.0v3'    "C:\\Program\\FnUsdShim.0.6.dll" is not valid, skipping. Reason: The system cannot find the path specified.  ENV VAR dlopen "C:\\Program\\FnUsdShim.0.6.dll"=0000000000000000FnUsdAbstraction error: FnUsdShim plugin failed to load, error=The specified module could not be found.    "Files\\Nuke16.0v3\\FnUsdShim.0.6.dll" is not valid, skipping. Reason: The system cannot find the path specified.  ENV VAR dlopen "Files\\Nuke16.0v3\\FnUsdShim.0.6.dll"=0000000000000000FnUsdAbstraction error: FnUsdShim plugin failed to load, error=The specified module could not be found.Fatal error - FnUsdShim PLUGIN LIB NOT FOUND, exiting.
 
Expected behavior:
For the nuke module to be imported in an external version of Python, like previous versions of Nuke could.
 
Actual behavior:
The FnUsdShim plugin cannot be found even when USG_SHIMLIB_PATH has been set, and the nuke module cannot be imported as a result.
Attempting to wrap the environment variable in quotes does not change the outcome (IE: set "USG_SHIMLIB_PATH=C:\Program Files\Nuke16.0v3").
 
Workaround:
Instead of using the USG_SHIMLIB_PATH environment variable, you can instead set the following variables and the nuke module should be imported successfully in an external Python installation on Windows
set PYTHONPATH=C:\Program Files\Nuke16.0v3\lib\site-packagesset USG_USD_LIB_PATH=C:\Program Files\Nuke16.0v3\FnUSD\libset USG_USD_PLUGIN_PATH=C:\Program Files\Nuke16.0v3\FnUSD\plugin\usdset USG_SHIMLIB_NAME=C:\Program Files\Nuke16.0v3\FnUsdShim.0.6.dll
 
On Linux systems however, running equivalent commands does not seem to work around the issue completely, and the following error will occur instead:
>>> import nuke--Initialize FnUsdShim--  plugin filename='/usr/local/Nuke16.0v3/libFnUsdShim.0.6.so'  ...explicit plugin file path(search paths disabled)='/usr/local/Nuke16.0v3/libFnUsdShim.0.6.so'  ENV FILENAME dlopen "/usr/local/Nuke16.0v3/libFnUsdShim.0.6.so"=0FnUsdAbstraction error: FnUsdShim plugin failed to load, error='libfoundryboost_python311.so.1.82.0: cannot open shared object file: No such file or directory'Fatal error - FnUsdShim PLUGIN LIB NOT FOUND, exiting. 
 
Reproduced by Support in:
Nuke 16.0v3 - Windows 11, Rocky 9
Nuke 15.2v1 - Windows 11
Nuke 15.1v1 - Windows 11
 
*macOS not tested as importing nuke as a module is unsupported on that OS
 
Earliest version tested:
Nuke 15.1v1 - This feature (FnUsdShim) did not exist before this version

    We're sorry to hear that

    Please tell us why