TouchDiffusion kept telling me Active engine: None. The engine was fine. The model files were fine. The cause was sys.path order.
The symptom chain
name 'StreamDiffusionWrapper' is not defined Numpy is not available Model load has failed. Doesn't exist. cannot access local variable 'pipe' where it is not associated with a value Active engine stayed None, Size (WxH) showed 0 0, and every Load engine did nothing.
Why it looks like the engine
TouchDiffusionExt imports the wrapper at DAT compile time inside a bare try/except. When the import fails, the class still compiles, StreamDiffusionWrapper is never bound, and every later call raises name 'StreamDiffusionWrapper' is not defined. The log only shows the deferred name error, not the real cause.
The real cause: host paths win
TouchDesigner inserts its own site-packages before any path the component adds, and on 2023 it also picks up the system Python 3.11 site-packages. The portable build of TouchDiffusion ships its own embedded_python with matched versions, so this is what happens:
- On TD 2025 the bundled numpy is 2.1.2. The
transformersin the portable env requiresnumpy<2, so the import chain aborts. - On TD 2023 numpy is fine, but the system Python contributes a torch 2.6 and a newer
huggingface_hubwithoutcached_download, which breaks the olderdiffusersin the portable env.
torch decides its numpy bridge at import time. That is why Numpy is not available is unrecoverable in-process, and why from_pretrained never returns a pipeline: pipe stays unbound and the wrapper dies on it.
What does not work
All of these were tried:
-
PYTHONPATHpointing at the portablesite-packages. TD's own paths still win. -
sitecustomize.py,usercustomize.py, or a.pthinside TD'ssite-packages. TD starts Python with thesitehooks not running;sitecustomizenever gets imported. -
sys.path.insertalone at the top of the Ext on TD 2025. Too late for numpy. - Deleting
torchfromsys.modulesand reimporting it. PyTorch asserts withTHPDtypeType.tp_dict == nullptr INTERNAL ASSERT FAILED at "torch/csrc/Dtype.cpp". - Calling
activate_streamfrom athreading.Thread. TD operators can only be touched on the main thread:SystemError: <td.OPShortcut> returned NULL.
What works
Tested on TD 2023.12600, Windows, RTX 4070 Laptop 8 GB, with the engines shipped in the portable build (512x512, batch 3).
- Launch TouchDesigner with
PYTHONNOUSERSITE=1so the system user site is out of the picture. - At the very top of the
TouchDiffusionExtDAT, before any import:
import sys SP = r"<PORTABLE>/embedded_python/Lib/site-packages" sys.path = [p for p in sys.path if not ("Programs" in p and "Python311" in p and "embedded" not in p)] if SP not in sys.path: sys.path.insert(0, SP) -
Re-init, select the engine,Load engine. The log should printTensorRT acceleration enabled.andEngine activated, andActive enginefills in.
Two side notes: Warning: '.venv/Lib/site-packages' is not a valid directory is harmless, the portable build uses embedded_python. And TouchDiffusion folder must be the portable root, the folder containing embedded_python/, StreamDiffusion/ and engines/, not its parent.
Credit
The numpy angle was already reported in issue #32, and the torch version angle in issue #38. The missing piece was path precedence, which is what issue #36 is about. The pipe error in issue #29 comes from building an engine in the web UI, a different flow.
![AMR Mechanical and Electrical Engineering — Ch.08: Contents {#contents .TOC-Heading} [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbtw3oxs45o0rlsdwb57q.png)
![AMR Mechanical and Electrical Engineering — Ch.10: Chapter 10. Battery and BMS [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1oq75ffn9xkv43oaf8j7.png)
![AMR Mechanical and Electrical Engineering — Ch.11: Contents {#contents .TOC-Heading} [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fonn99mga9ifg36liirww.png)
![AMR Mechanical and Electrical Engineering — Ch.13: Contents {#contents .TOC-Heading} [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6h1hrp24iuq1ixb1m2xd.png)
![AMR Mechanical and Electrical Engineering — Ch.15: Chapter 15. EMI / EMC Design [KR]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fibat7i5er6079kccmeqf.png)