Q100398: Implementing PySide scripts into Nuke 11
When launching a Python script with Nuke 11, if your Nuke script requires Python's PySide module then Nuke will throw an exception which will prevent it from opening.
Displayed below, the following exception occurs on Nuke launch if a PySide module is imported in Nuke's
Within Nuke's launch terminal, an
ImportErrorwill be shown specifying that Nuke could not import a PySide module, in this case,
With the release of Nuke 11, there have been significant library updates done with the aim of making Nuke VFX Reference Platform 2017 complaint.
In the case of the PySide, this was updated from PySide 1.2.2 to PySide 2.0 within the Nuke core libraries, so it can now be imported as Pyside2 rather than PySide. For more information on the library versions shipped with Nuke 11, see Appendix D in the Online Help.
As a result of this update from PySide to PySide2, starting with Nuke 11 PySide modules are no longer callable.
has been replaced with:
Additionally, the definition of some classes has been moved between modules. This particularly affects any GUI related classes, which have mostly been moved from
PySide2.QtWidgets, however, there are other modules that have been relocated as well.
To resolve the
ImportErrorexception when launching Nuke, any scripts within your '.nuke' folder which use PySide, will need to be altered to catch the exception before execution.
Handling the exception can be done by modifying the import statements to call a
exceptfunction, and catch the
ImportErrorwhen importing the PySide modules.
If the exception is caught, calls can be added to import the PySide2 equivalent functions, which will prevent the
ImportErrorerror on startup.
As mentioned in the Cause section, some of the GUI related functions have been moved to other modules. The PySide module used for all GUI related tasks,
PySide.QtGui, has mostly been moved to the
In most cases when using this module, to avoid the
ImportErrorwithin Nuke, and instead of refactoring each
Pyside.QtGuifunction in your script, you should now import
This can be set up as displayed in the following snippet:
try: from PySide import QtGui, QtCore except ImportError:
from PySide2 import QtCore
from PySide2 import QtWidgets as QtGui
This allows older PySide code to run in PySide2, as most of the QtGui functions have moved to the QtWidgets module.
To make sure scripts using PySide modules work correctly in Nuke 11, you need to complete the transition and all
PySidefunctions will need to be refactored as
If you would like to have code compatibility when using PySide and PySide2 across both Nuke 10.5 and Nuke 11, the Qt.py project provides a process which switches the PySide and PySide2 modules, depending on your Nuke version.
NOTE: The Qt.py project is created by a third party and as such, any problems or questions need to be reported to the third party project owners.
If you would like to know more about handling exceptions, you can access the Python documentation on exceptions at the following link: Python Documentation - Handling Exceptions
If your script uses the
PySide2.QtWebEngine, unfortunately, the module is currently not implemented into Nuke 11 and it won't work. More information regarding this can be found here:
We're sorry to hear thatPlease tell us why