Q100715: How to address Python PySide issues in Nuke 16+

SYMPTOMS

When launching Nuke 16 or later, if you have custom Python code which uses PySide2, then you will encounter an error on launch as the plug-in fails:

If you are launching with a Command Prompt or Terminal, then you will also see something like this error saying: ModuleNotFoundError: No module named 'PySide2':


CAUSE

With the update to VFX Reference Platform 2024 in Nuke 16, the PySide library has been updated to PySide6. This means that the PySide module now has a new name to import.

This was similar to when Nuke 11 moved from PySide to PySide2 with the VFX Reference Platform 2017 update. More information about that can be found in our article here: Q100398: How to overcome issues using PySide Python scripts in Nuke 11+

 

RESOLUTION

To address this, your code will need to be updated to work with PySide6.

For many cases, you can replace:

import PySide2

with:

import PySide6

This should address the vast majority of the issues, as unlike the upgrade from PySide to PySide2, there are no large module changes.

One notable change which may affect users is that the QAction class has moved from PySide2.QtWidgets to PySide6.QtGui, which is used for menu actions inside Nuke's UI.

There are also some other changes which may need addressing in your code, if you are using the affected modules or functions. More information about this can be found on Qt for Pythons’ website here: https://doc.qt.io/qtforpython-6/faq/porting_from2.html

 

Alternatively, you could use the third party Qt.py to help with mapping between all the different PySide/PyQt library versions, making your code library versions agnostic.

So lines like:

from PySide2 import QtWidgets, QtCore, QtGui

Would become:

from Qt import QtWidgets, QtCore, QtGui

Providing Qt.py is available in your Nuke path, this should allow you to import the module between different Nuke versions without having to change the code to be Nuke version specific. Qt.py can be found on GitHub here: https://github.com/mottosso/Qt.py

NOTE: The Qt.py project is created by a third party and as such, any problems or questions need to be reported to the project owners.

 

FURTHER READING 

Other third party guides about how to convert from PySide2 to PySide6 can also be found below:

https://erwanleroy.com/updating-your-python-scripts-for-nuke-16-and-pyside6/

https://www.pythonguis.com/faq/pyside2-vs-pyside6/

    We're sorry to hear that

    Please tell us why