Import external module issue

Hi all, I’m having trouble to import module in TD. I failed to solve it. Hope someone here could give some tips. Thank you very much in advance!

I have a virtual environment. Other modules like numpy, pandas work well in TD.
However when I tried simplet5 module, it failed.
I use pip install in my conda environment and it worked well outside of TD in jupyter notebook. I managed to import it and use it in jupyter notebook.
However in TD, it threw the error:

Traceback (most recent call last):
File “</project1/loadmodel:op(‘/project1/loadmodel’).run()>”, line 1
td.tdError: File “/project1/loadmodel”, line 1
r = previousimport(*args, **kw)
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\simplet5_init_.py”, line 1
from .simplet5 import SimpleT5
r = previousimport(*args, **kw)
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\simplet5\simplet5.py”, line 4
from transformers import (
r = previousimport(*args, **kw)
File “”, line 1055, in _handle_fromlist
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\file_utils.py”, line 2694, in getattr
module = self._get_module(self._class_to_module[name])
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\file_utils.py”, line 2704, in get_module
return importlib.import_module(“.” + module_name, self.name)
File "C:\Program Files\Derivative\TouchDesigner.2022.24200\bin\lib\importlib_init
.py", line 127, in import_module
return bootstrap.gcd_import(name[level:], package, level)
File "C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\models_init
.py", line 19
from . import (
r = previousimport(*args, **kw)
File "C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\models\layoutlm_init
.py", line 22
from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig
r = previousimport(*args, **kw)
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\models\layoutlm\configuration_layoutlm.py”, line 19
from transformers import PretrainedConfig, PreTrainedTokenizer, TensorType
r = previousimport(*args, **kw)
File “”, line 1055, in _handle_fromlist
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\file_utils.py”, line 2694, in getattr
module = self._get_module(self._class_to_module[name])
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\file_utils.py”, line 2704, in get_module
return importlib.import_module(“.” + module_name, self.name)
File "C:\Program Files\Derivative\TouchDesigner.2022.24200\bin\lib\importlib_init
.py", line 127, in import_module
return _bootstrap.gcd_import(name[level:], package, level)
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\tokenization_utils.py”, line 27
from .tokenization_utils_base import (
r = previousimport(*args, **kw)
File “C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\transformers\tokenization_utils_base.py”, line 77
from tokenizers import AddedToken
r = previousimport(*args, **kw)
File "C:\Users/studio/anaconda3/envs/td-tfgpu/Lib/site-packages\tokenizers_init
.py", line 79
from .tokenizers import (
r = previousimport(*args, **kw)
pyo3_runtime.PanicException: assertion failed: !handle.is_null()
Results of run operation resulted in exception.

I printed the sys paths. The simplet5 is in the folder.
I failed to find out why it failed to import in TD.
Anyone can help? Thank you so much!

Hey @akihiko

Sorry with the delay in answering during the holidays.

I am unable to reproduce at the moment with a simple setup.

Could you please share your import script as well as describe how you link your Anaconda environment with the TouchDesigner process?

What methods of SimpleT5 are you using ?

Do you get this error message as soon as you call “from SimpleT5 import SimpleT5” ?

Here is a screenshot of a simple setup that works, inspired from the following tutorial: Anaconda - Managing Python Environments and 3rd-Party Libraries in TouchDesigner | Derivative

Best,
Michel

Hi @JetXS , thank you so much for your help! I figured it out yesterday which turned out to be the version conflict problem. Thank you so much for your time!

By the way, I am tring using the h5 model in TD. However TD seems not recognize the installed h5py. Same case as this post: FIXED: ImportError: `load_weights` requires h5py when loading weights from HDF5 - #13 by Deltacut

I am using conda virtual environment. Other modules work well but I failed on the h5py. It keeps asking me to install it which already is installed. It works well outside of TD.
Do you know how to solve it? Thank you so much!

1 Like