Python scripts for Nuke 16+ and PySide6

ModuleNotFoundError: No module named 'PySide2' on Nuke16+

Useful guide to update python tools for Nuke 16+ and PySyde 6

With Foundry’s release of Nuke 16, the interface framework has moved from PySide2 (Qt5) to PySide6 (Qt6). If you open an older Python script (for example a Nukepedia tool such as Stamps), you might see this error when you try to launch Nuke 16 or above:



With the release of Nuke 16, Foundry made an important update that affects all custom Python tools: the switch from PySide2 to PySide6. If you use scripts from Nukepedia — like Stamps — you’ve probably seen this error after upgrading:

ModuleNotFoundError: No module named 'PySide2'

This simply means that the old PySide2 module is no longer available in Nuke 16. Below there are three very simple things you can do to fix it or learn more.


In this zip file you will find a couple of examples how you have to update your tools for Nuke 16+ or Qt:
Download examples





01. Quick fix for users

The fastest way to get a script working again (like Stamps or other Nukepedia tools) is to update the import lines at the top of the Python file. Open the script and replace any old PySide2 imports with this pattern. For example you can replace

import PySide2

with :

import PySide6


So if you get the previous error with the Stamp.py at the line 59, Open the script file (.py) with a simple Text Editor and replace any old PySide2 imports with the following code. This will let Nuke 16 use PySide6 and keep compatibility with older versions:


#OLD CODE TO REPLACE
try:
    if nuke.NUKE_VERSION_MAJOR < 11:
        from PySide import QtCore, QtGui, QtGui as QtWidgets
        from PySide.QtCore import Qt
    else:
        from PySide2 import QtWidgets, QtGui, QtCore
        from PySide2.QtCore import Qt
except ImportError:
    from Qt import QtCore, QtGui, QtWidgets
  
  
#REPLACE WITH THIS
  try:
    if nuke.NUKE_VERSION_MAJOR < 11:
        from PySide import QtCore, QtGui, QtGui as QtWidgets
        from PySide.QtCore import Qt
    elif nuke.NUKE_VERSION_MAJOR < 16: 
        from PySide2 import QtWidgets, QtGui, QtCore
        from PySide2.QtCore import Qt
    else:
        from PySide6 import QtWidgets, QtGui, QtCore
        from PySide6.QtCore import Qt
except ImportError:
    from Qt import QtCore, QtGui, QtWidgets
	
	

This means Nuke 16+ will use PySide6, and older versions of Nuke (which still have PySide2) will fall back safely. It’s a simple change and fixes the “No module named PySide2” error in most cases
Save the file, restart Nuke, and your tool should work again. This fix is perfect for small tools like Stamps, SwitchTab or other Nukepedia scripts.



02. QT: Clean option for tool authors

If you create or maintain tools, you can make them future-proof using Qt.py — a lightweight compatibility layer that automatically loads the correct Qt version. Once installed, you can simply write:

from Qt.QtWidgets import QPushButton

Qt.py on GitHub works with PySide, PySide2, PySide6 and PyQt, and it keeps your code clean and compatible across multiple Nuke versions and other DCCs.




Leave a comment