Script TOP Crashing While Using Custom Python Environment for OpenCV in TouchDesigner

Hi everyone,

I’ve been working on a project in TouchDesigner and encountered a persistent issue with the Script TOP crashing the whole application. I wanted to share my setup and challenges here to see if anyone has advice or suggestions.

Here’s what I’ve done so far:

  1. I created a separate Python environment using Conda specifically for this project.
  2. I configured the custom Python environment by setting the path in Menu Bar > Edit > Preferences > Python 64-bit Module Path.
  3. However, even after setting this, TouchDesigner still defaults to its built-in Python environment.

To work around this, I followed a tutorial (Anaconda - Managing python environments and 3rd-party libraries in TouchDesigner) and used an Execute DAT to force TouchDesigner to only use my custom Python environment. Despite this, the Script TOP crashing issue persists.

My main goal is to use the OpenCV-based DeepFace package in TouchDesigner, which doesn’t currently have a native derivative. I’m wondering:

  • Is there a better way to manage and integrate a custom Python environment in TouchDesigner?
  • Has anyone successfully used packages like DeepFace or OpenCV in a custom setup without running into crashes?

Below is my System Details:

  • TouchDesigner Version: 2023.12000 (current newest stable build)
  • Operating System: Windows 10
  • GPU: NVIDIA GeForce RTX 4080 (Laptop GPU)
  • GPU Driver Version: 551.95
  • Custom Python Environment:
    • Created using Conda
    • Python version: 3.11
    • Key packages: NumPy (2.0.2), OpenCV, DeepFace

I’d really appreciate any advice, solutions, or insights from your experience! Thank you in advance for your help! Wishing everyone a wonderful holiday season!

NumPy and OpenCV are part of TouchDesigner.

When you sideload an environment made with Anaconda and use the script you mention, you tell that your custom packages, possibly of different versions, have the priority over what we ship.

Depending on load order, backward and forward compatibility, it might or might not have an impact. If part of TouchDesigner requires the package version loaded by default with TouchDesigner but your script load a different version, this is where a crash might happen.

While users can use third party packages, we don’t guarantee that all will work smoothly or that they will even load in TouchDesigner.

I will have a look to see if anything can be done about this library you mention but no promise and no specific ETA.

Best,
Michel

1 Like

In my conda-implementation for TD I am experimenting with “Mounting” the environment before importing the module. This also includes the possibility for savely overwriting the imported modules.
As I said, still testing but you can try doing the following (I implemented it as an context manager, but you should be able to run it raw.

import sys
# Clear imported modules.
saveModules = sys.modules.copy()
sys.modules = {}
# Insert site packages at position 0 to be searched first.
savePath = sys.path.copy()
sys.path.insert(
	0,
	$PathToSitePackages
)

# Your logic
import MyModule
# etc. This is where your stuff is happening

sys.modules = saveModules
sys.path = savePath

# onCook() etc could be placed here, using myModule.
1 Like

Hi @Rooooose

Can you share your example file / script ?

It’s loading fine here. But the library can use various detectors and all so that might be an issue in a method. Or a method that needs threading.