Q100465: How to load plugins for different versions of Nuke

SUMMARY

This article will outline two different methods for how you can load different plugin directories for multiple versions of Nuke.

This may be helpful if you are using multiple different versions of Nuke simultaneously, as you may find that some third party plugins are not compatible with all of the versions of Nuke that you are using.

As of Nuke 13.0v1, Python 2 is no longer supported so this may also help while you are updating your Python scripts to be compatible with Python 3.7, and the same principle also applies when updating Python code for the change from PySide2 to PySide6 in Nuke 16.0v1.

 

MORE INFORMATION

Firstly, you will need to save your plugins in different directories for each Nuke version. You can then add the additional directories for Nuke to load upon launch.

Any plugins that you wish to load only for specific versions of Nuke should not be added into into the top level of your local ~/.nuke folder, as this directory is always loaded (unless you are running in safe mode).

There are two methods that you can use to load plugins for different versions of Nuke:

  1. Creating a Python Startup Script 

    Plugin directories can be added via Python by using the pluginAddPath() method for Nuke, or the addPluginPath()method for Nuke Studio and Hiero. 

  2. Creating an Environment Variable Wrapper Script

    Alternatively, a custom wrapper script can be used to launch specific versions of Nuke, Nuke Studio, or Hiero with an environment variable pointing toward the desired plugins.

The primary difference between the results of these two methods is their evaluation order. Using pluginAddPath() will add the directories to the front of Nuke’s plugin path, while using an environment variable will add the directory after your ~/.nuke directory. The following is an example of running nuke.pluginPath() in the Script Editor with two directories added to Nuke’s plugin path, one added via Python and one set with an environment variable:

Which method you decide to use would depend on your current pipeline environment and any dependencies that your plugins may rely on.


 

Creating a Python Startup Script

By using your init.py file, you can define which plugin path is loaded on launch for a given Nuke version.

Here is an example of the Python code that will check if you have launched Nuke 13 or Nuke 16 and load the plugin path accordingly:

import nuke

if nuke.NUKE_VERSION_MAJOR==16:
nuke.pluginAddPath("/path/to/plugins/folder/nuke16")

if nuke.NUKE_VERSION_MAJOR==13:
nuke.pluginAddPath("/path/to/plugins/folder/nuke13")


The above code will only check the major version of Nuke you are running (Nuke 13, Nuke 16, etc.) but by using an and statement and NUKE_MINOR_VERSION, you can be more specific with what Nuke versions will launch certain plugins. For example, the following code will check if the Nuke version is 15.1 before loading the plugin path if the version matches:

import nuke

if nuke.NUKE_VERSION_MAJOR==15 and nuke.NUKE_VERSION_MINOR==1:
nuke.pluginAddPath("/path/to/plugins/folder/nuke151")


You can also check for the full Nuke version by using NUKE_VERSION_STRING, like so:

import nuke

if nuke.NUKE_VERSION_STRING=="16.0v4":
nuke.pluginAddPath("/path/to/plugins/folder/nuke160v4")

 

Nuke Studio & Hiero

Similar to creating the plugin paths for Nuke, for Nuke Studio and Hiero you can do this by writing an if statement that checks which version of Nuke Studio/Hiero has been launched and load the plugin paths accordingly.

However, rather than adding this code to your ~/.nuke/init.py file, it needs to be saved into a .py file inside of your ~/.nuke/Python/Startup or ~/.nuke/Python/StartupUI directories. You can find more information about adding plugin paths to Nuke Studio and Hiero in the following article: Q100373: How to add extra plug-in paths to Nuke Studio and Hiero.

NOTE: The additional directories that you are loading will also need to contain the same /Python/Startup or /Python/StartupUI folder structure as your ~/.nuke folder.

The following is an example for setting up different plugin paths to be loaded for Nuke Studio/Hiero 13 or 16:

import hiero
from hiero.core import env

if env["VersionMajor"]==16:
# scripts saved in /path/to/plugins/folder/hiero16/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero16")

if env["VersionMajor"]==13:
# scripts saved in /path/to/plugins/folder/hiero13/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero13")


Like with Nuke, you can use env["VersionMinor"] with an and statement to define the plugin path for a major and minor version. For example, the following code will load the plugin path for all Nuke Studio/Hiero 15.1 versions:

import hiero
from hiero.core import env

if env["VersionMajor"]==15 and env["VersionMinor"]==1:
# scripts saved in /path/to/plugins/folder/hiero151/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero151")

You could also load the plugins based on the exact version by using env["VersionString"]. However, please note that the result of env["VersionString"] also includes the product name (for example "Hiero 16.0v4" or "NukeStudio 16.0v4"):

import hiero
from hiero.core import env

if env["VersionString"].endswith("16.0v4"):
# scripts saved in /path/to/plugins/folder/hiero160v4/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero160v4")

 

Creating an Environment Variable Wrapper Script

A wrapper script embeds system commands or utilities into an executable file from which you can then repeatedly invoke the commands, without having to retype it in the command line. In this case, you can set the NUKE_PATH environment variable and launch the application. Setting the environment variable via a wrapper script means that the commands are only enabled for that active command line session and it is not permanently set on your system.

The wrapper scripts can be saved anywhere on your machine and can be executed by running them in the terminal. You could also set these files to be opened in the terminal by default so you can execute them by double clicking on it.

The wrapper scripts for macOS and Linux contain very similar commands, with the Nuke application directory being the biggest difference between the two operating systems. Examples scripts for Nuke 16.0v4 on each operating system can be found below:

TIP: The same principle applies to Nuke Studio and Hiero, which can be launched by adding the --hiero or --studio launch flags to these scripts.

macOS:

#! /bin/bash
export NUKE_PATH=/path/to/some/folder/
/Applications/Nuke16.0v4/Nuke16.0v4.app/Contents/MacOS/Nuke16.0

Linux:

#! /bin/sh
export NUKE_PATH=/path/to/some/folder/
/usr/local/Nuke16.0v4/Nuke16.0

This is quite different from Windows, where you would need to create a script that runs the commands in the Windows Command Prompt. To do this, you can create a batch file (.bat) which contains the following commands:

Windows:

set NUKE_PATH=\path\to\some\folder
"C:\Program Files\Nuke16.0v4\Nuke16.0.exe"

NOTE: You can also find example wrapper scripts for each operating system attached to this article.

 

  

FURTHER READING

More information about loading plugins in Nuke can be found in the following pages of our documentation:


 

EXAMPLE FILES

    We're sorry to hear that

    Please tell us why