NumPy ImportError and _ARRAY_API Not Found Error - Issues with PyTorch and Transformers in TouchDesigneㄱ

I am currently working on a project in TouchDesigner 2023.11880 that utilizes PyTorch, Transformers, and OpenCV. However, I am encountering an issue related to NumPy when running the code, and I’m hoping for some assistance.

The error message I receive is as follows:

td.tdError: C:\Program Files\Derivative\TouchDesigner.2023.11880\bin\Lib\site-packages\transformers\cache_utils.py:1879: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at …\torch\csrc\utils\tensor_numpy.cpp:84.)
offload_device: Union[str, torch.device] = torch.device(“cpu”),
AttributeError: _ARRAY_API not found
ImportError: numpy.core.multiarray failed to import

It seems that there is an issue with importing numpy.core.multiarray, possibly related to dependency conflicts between NumPy, PyTorch, and OpenCV.

Steps I’ve Tried:

  1. Reinstalling NumPy, PyTorch, and OpenCV: I’ve reinstalled these libraries in the internal Python environment of TouchDesigner.
  2. Downgrading NumPy: I attempted using older versions like numpy==1.21.0, but the issue persists.
  3. Checking GPU Settings: I’ve ensured that TouchDesigner runs in either GPU or CPU mode, but it didn’t resolve the issue.

Environment:

  • TouchDesigner 2023.11880
  • Python 3.11 (built-in TouchDesigner environment)
  • External libraries: NumPy, PyTorch, OpenCV, Transformers, etc.

If anyone has experience with this issue or can suggest a solution, I would greatly appreciate your help.

Thank you!

Hi - there is currently an issue with PyTorch when used as a sideloaded environment. Reported on Github and PyTorch forums. It seems to affect Pytorch > 2.2.x

Which version of Pytorch are you using ?

Additionally, how do you make all those packages part of your search path?

EDIT: After having a second look, I see that you are loading libraries from TouchDesigner’s own site-package. This is quite risky and error prone. What pushed you to go this way ? You should prioritize approaches explained in our documentation: Python - Derivative

We cannot provide support for TouchDesigner installation folders being modified.