Shotgrid with tk-blender

Hello,
i’m new to shotgrid and i have been trying to integrate tk-blender in it. it’s working perfectly fine on windows, but using the same env configs on linux (centOS and Rocky Linux), i can’t get the menu to show, nor the blender icon in the shotgrid desktop app.
i’ve tried almost everything, it is installing the engine from git, i’ve changed blender versions alot, still to no avail.
thank you in advance

First of all, you need to make sure to also pip install Pyside2 inside Blender or bundle it in the environment, as mentioned in tk-blender’s github repo readme.

Apart from that, you should enable debug logging and see if the logs will tell you where to look.
Without logs there is not much to go on.

Feel free to post them here.

1 Like

thank you so much for the fast reply, i have made sure that pyside is installed on every python installed in the machine (globally installed python, Blender’s python and Shotgrid’s python), i have also enabled debug mode, but there’s neither errors or warnings, whether related to tk-blender or anything else, that’s what’s frustrating me here.
blender isn’t even showing on the desktop app,but on. “tank caache_apps” it says that it downloaded from. the repo and installed correctly.

is there anything i can assist with for a clearer overview ? logs ? env files ?

Have you set the engine to tk-blender in the software entities?

What version of blender are you using?
Are you pointing it to the right install location?

On Windows and Mac it searches the default locations but not sure it does so for Linux or if they are the correct locations.

Hi guys @Diego_Garcia_Huerta I am using Blender 4 but the menu in blender seems to have issues. Is it possible to get the integration working in Blender 4?

So I got the menu up and it’s working but all the add-ons are disabled. Any idea why?

You’d probably want to look at the Blender Log files and the sgtk log files.

Thanks Ricardo. I managed to get it working. PySide2 latest verison cmpatible with Python 3.10 only. I dialled back to that version of Python and it’s good to go.

1 Like

And only with Blender 4.0. 4.1 seems to have an api change that does… stuff.

1 Like

PySide2 is not supported in Python 3.11 (Blender 4.1) and later versions and cannot be easily installed using pip. However, it might be possible to use PySide6 instead. This switch would require updating the core, frameworks, and applications to more recent versions than those we are currently using, making it untestable for me at this moment. Additionally, some adjustments in the tk-blender engine might be required…

1 Like

Blender 4.1 works fine after updating the Shotgun_menu.py script to support PySide6 and installing the xcb-cursor library (dnf install xcb-util-cursor). This resolved the issue I was experiencing.

try:
    from PySide2 import QtWidgets, QtCore

    PYSIDE2_IMPORTED = True
except ModuleNotFoundError:
    try:
        from PySide6 import QtWidgets, QtCore

        PYSIDE2_IMPORTED = True
    except ModuleNotFoundError:
        PYSIDE2_IMPORTED = False
3 Likes

Windows has a specific issue where PySide6 in Blender crashes due to the QtWebEngine components, and tk-core does not respect the SHOTGUN_SKIP_QTWEBENGINEWIDGETS_IMPORT environment variable when importing PySide6.
To prevent the import of QtWebEngine in tk-blender, we use the following approach:

PYSIDE6_IMPORTED = False
try:
    from PySide2 import QtWidgets, QtCore

    PYSIDE2_IMPORTED = True
except ModuleNotFoundError:
    try:
        if sys.platform == "win32":
            # avoid loading QtWebEngine on Windows!
            import PySide6
            class QtWebEngineCore:
                QWebEnginePage = None
                QWebEngineProfile = None
            PySide6.QtWebEngineCore = QtWebEngineCore
            PySide6.QtWebEngineWidgets = None
        
        from PySide6 import QtWidgets, QtCore
        
        PYSIDE2_IMPORTED = True
        PYSIDE6_IMPORTED = True
    except ModuleNotFoundError:
        PYSIDE2_IMPORTED = False

Additionally, monkey patch the tk-core QtImporter to override _import_pyside6:

def boostrap():
    # start the engine
    SGTK_MODULE_PATH = os.environ.get("SGTK_MODULE_PATH")
    if SGTK_MODULE_PATH and SGTK_MODULE_PATH not in sys.path:
        sys.path.insert(0, SGTK_MODULE_PATH)

    engine_startup_path = os.environ.get("SGTK_BLENDER_ENGINE_STARTUP")
    engine_startup = imp.load_source("sgtk_blender_engine_startup", engine_startup_path)
    
    if PYSIDE6_IMPORTED and sys.platform == "win32":
        # avoid loading QtWebEngine on Windows!
        def _import_pyside6(self):
            """
            Import PySide6.
            HACK - do not import QtWebEngine* in Windows!!!

            :returns: The (binding name, binding version, modules) tuple.
            """

            import PySide6
            import pkgutil

            sub_modules = pkgutil.iter_modules(PySide6.__path__)
            modules_dict = {}
            for module in sub_modules:
                module_name = module.name
                if "QtWebEngine" in module_name:
                    continue
                try:
                    wrapper = __import__("PySide6", globals(), locals(), [module_name])
                    if hasattr(wrapper, module_name):
                        modules_dict[module_name] = getattr(wrapper, module_name)
                except Exception as e:
                    logger.debug("'%s' was skipped: %s", module_name, e)
                    pass

            return (
                PySide6.__name__,
                PySide6.__version__,
                PySide6,
                modules_dict,
                self._to_version_tuple(PySide6.__version__),
            )
        
        from tank.util.qt_importer import QtImporter
        QtImporter._import_pyside6 = _import_pyside6

    # Fire up Toolkit and the environment engine.
    engine_startup.start_toolkit()
1 Like

I’ve been trying to get PySide6 working with Blender and have tried several methods, but I’m running into some issues with specific modules. I think the problem might be related to the installation path.

Could you please share the path where you installed PySide6?

updated++
I installed PySide6 using this command C:\Program Files\Blender Foundation\Blender 2.82\2.82\python\bin\python.exe -m pip install PySide6 and Now I can see Shotgun menu but it’s empty and I got this error…

Mon Sep  2 14:10:14 2024 | Debug | Shotgun Blender Engine | Debug: Shotgun tk-blender: Initializing engine... <Sgtk Engine 0x23557ce0a10: tk-blender, env: project>
Mon Sep  2 14:10:14 2024 | Debug | Shotgun Blender Engine | Debug: Shotgun tk-blender: Importing python modules in C:\Users\sungbin\AppData\Roaming\Shotgun\bundle_cache\git\tk-blender.git\v2.0.0\python...
Mon Sep  2 14:10:15 2024 | Error | Shotgun Blender Engine | Shotgun: Could not start engine. Details: 'NoneType' object has no attribute 'QApplication'Traceback (most recent call last):
  File "C:\Users\sungbin\AppData\Roaming\Shotgun\bundle_cache\git\tk-blender.git\v2.0.0\startup\bootstrap.py", line 104, in start_toolkit_classic
    engine = sgtk.platform.start_engine(env_engine, context.sgtk, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/sungbin/AppData/Roaming/Shotgun/icentric-dev/p70c463.basic.desktop/cfg/install/core/python\tank\platform\engine.py", line 3013, in start_engine
    return _start_engine(engine_name, tk, None, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/sungbin/AppData/Roaming/Shotgun/icentric-dev/p70c463.basic.desktop/cfg/install/core/python\tank\platform\engine.py", line 3173, in _start_engine
    engine = class_obj(tk, new_context, engine_name, env)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sungbin\AppData\Roaming\Shotgun\bundle_cache\git\tk-blender.git\v2.0.0\engine.py", line 232, in __init__
    Engine.__init__(self, *args, **kwargs)
  File "C:\Users/sungbin/AppData/Roaming/Shotgun/icentric-dev/p70c463.basic.desktop/cfg/install/core/python\tank\platform\engine.py", line 198, in __init__
    self.pre_app_init()
  File "C:\Users\sungbin\AppData\Roaming\Shotgun\bundle_cache\git\tk-blender.git\v2.0.0\engine.py", line 325, in pre_app_init
    self.init_qt_app()
  File "C:\Users\sungbin\AppData\Roaming\Shotgun\bundle_cache\git\tk-blender.git\v2.0.0\engine.py", line 465, in init_qt_app
    self._qt_app = QtGui.QApplication.instance()
                   ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'QApplication'

I ended up resolving the issue caused by PySide6 installation prbolems and tk-core’s inability to load PySide6. By updating to the latest tk-core version (v0.21.6), the GUI now functions properly in Blender 4.2.

Since the original repository seems to be unmaintained, I create a new repository. You can find it here: GitHub - icentric-dev/tk-blender: 🥛 FPTR Toolkit Engine for Blender: https://www.blender.org/

2 Likes

I’m also using some fixes/updates that are not a part of the original repositary.
Related thread:

1 Like