Hi everyone!
I am having the following error "ImportError: cannot import name ‘_imaging’ from ‘PIL’ ", I state that I tried all possible ways (install the latest version of the library in question, assign the relative path to site-packages in TouchDesigner, follow Matthew Ragan’s tutorial regarding the 'importing libraries etc) but I couldn’t fix the problem.
I use the latest version of TD on macbook pro M1pro with MacOs Ventura.
Can someone help me please?
Thanks in advance
What’s the output in TD textport when you run this?
import PIL
print(PIL.__version__)
Hi! this is the result: 10.0.0
That sounds like all is good.
So perhaps the way you try to import is incorrect.
Try putting something basic like this in a Text DAT and run it (keep textport open to see output)
(Replace “anyfile.jpg” with a real path on your machine to a jpg file)
from PIL import Image
# Location of the image
img = Image.open("anyfile.jpg")
# size of the image
print(img.size)
# format of the image
print(img.format)
Here the result:
Traceback (most recent call last):
File "</project1/text1>", line "op('/project1/text1').run()"
td.tdError: File "/project1/text1", line 1
r = previousimport(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/paolopastorino/anaconda3/lib/python3.10/site-packages/PIL/Image.py", line 82
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/Users/paolopastorino/anaconda3/lib/python3.10/site-packages/PIL/__init__.py)
Results of run operation resulted in exception.
in line 6 of that error I see you have installed Python 3.10.
It is essential that you install the same version as TD uses - which currently is 3.9 for TD official release.
See the Derivative documentation on installing custom Python packages here:
Ah, so instead of official release of TD you are running the latest experimental (unstable) release of TD, which is built on Python 3.11
This means you need to install Python 3.11 alongside it.
Having said that, if you’re a beginner I would recommend running the official release of TD so you don’t encounter unexpected bugs or unstable parts of the experimental release of TD.
I solved the problem (I always use the experimental version of TD and the latest version of Python).
All the modules needed to run my script (stable diffusion API) I installed with the pip command and these modules were installed inside the homebrew python framework, for this reason TD didn’t have access to those modules.
There are two alternatives:
- tell TD the site-packages path of the homebrew pythonframework.
- copy the modules into the TD site-packages once installed in the above path.
Thanks anyway for being available!
Ah well done! I was looking for other stuff as in the first post you said you already assigned the siite-packages folder in TD. Happy you got it working.