Create a ticket

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 file:
Within Nuke's launch terminal, an ImportError will be shown specifying that Nuke could not import a PySide module, in this case, PySide.QtCore:



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.
For example:
import PySide.some_module
has been replaced with:

import PySide2.some_module
Additionally, the definition of some classes has been moved between modules. This particularly affects any GUI related classes, which have mostly been moved from PySide.QtGui to PySide2.QtWidgets, however, there are other modules that have been relocated as well.


To resolve the ImportError exception 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 try and except function, and catch the ImportError when importing the PySide modules.
If the exception is caught, calls can be added to import the PySide2 equivalent functions, which will prevent the ImportError error 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 PySide2.QtWidgets module. 
In most cases when using this module, to avoid the ImportError within Nuke, and instead of refactoring each Pyside.QtGui function in your script, you should now import PySide2.QtWidgets as QtGui instead.
This can be set up as displayed in the following snippet:

    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 PySide functions will need to be refactored as PySide2 versions. 
If you would like to have code compatibility when using PySide and PySide2 across both Nuke 10.5 and Nuke 11, the project provides a process which switches the PySide and PySide2 modules, depending on your Nuke version. 
NOTE: The 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: 
Was this article helpful?
0 out of 0 found this helpful