Nuke as a Python Module

You can import Nuke as a module into a third-party Python 3.11.7 interpreter, granting full access to the Nuke Python-API, but from within a native Python interpreter instead of Nuke.

Note:  Importing Nuke as a Python module is unavailable on macOS. Instead, use the Python build that ships with Nuke, which can be found here:
/Applications/Nuke16.0v4/Nuke16.0v4.app/Contents/MacOS/python.app

Note:  Foundry cannot provide customer support for third-party Python interpreters.

Windows Setup

1.   To import the Nuke module into a third-party Python interpreter, you can add C:\Program Files\Nuke<version> to your PATH environment variable. See Environment Variables for more information.
2.   In Version 15.1 and higher you also need to ensure the USD dependencies can be found. This can be done by setting the following environment variables:
a. USG_SHIMLIB_PATH to C:\Program Files\Nuke<version>
b. USG_USD_LIB_PATH to C:\Program Files\Nuke<version>\FnUSD\lib
c. USG_USD_PLUGIN_PATH to C:\Program Files\Nuke<version>\FnUSD\plugin\usd
3.   Add the file path for Nuke's site-packages directory to the usrlocal.pth file in your Python 3.11.7 install. This is done by adding C:\Program Files\Nuke<version>\lib\site-packages to the usrlocal.pth file. Alternatively, you can add C:\Program Files\Nuke<version>\lib\site-packages python to your PYTHONPATH environment variable.

Tip:  You can also use relative paths to the directory containing the usrlocal.pth file.

Note:  If you encounter problems with FnUsdShim.X.Y.dll not being found then try setting USG_SHIMLIB_NAME to C:\Program Files\Nuke<version>\FnUsdShim.X.Y.dll . X and Y can be found by examining the name of that dll in the directory. Then delete the USG_SHIMLIB_PATH environment variable.

Linux Setup

1.   To import the Nuke module into a third-party Python interpreter, you can add <path_to_nuke> to your LD_LIBRARY_PATH environment variable. See Environment Variables for more information.
2.   Add the file path for Nuke's site-packages directory to the usrlocal.pth file in your python 3.11.7 install site-packages directory. For Python 3.11.7, for example, this is done by adding <path_to_nuke>/lib/python3.11/site-packages to the usrlocal.pth file. Alternatively, you can add <path_to_nuke>/lib/python3.11/site-packages python to your PYTHONPATH environment variable.

Usage

At the Python prompt, use the import nuke declaration to make Nuke’s Script Editor functions and commands (such as nuke.nodes.Blur() to add a Blur node) available in your chosen Python interpreter.

The import nuke function checks-out a nuke_r render license by default. If you want to use Nuke interactively, and you have a nuke_i license, set the NUKE_INTERACTIVE environment variable to 1.

For more information, see Nuke as a Python Module in the Nuke Developer Guide.