Hello. I am importing the google cloud speech module and am having some trouble with imports. I have included external python path so my sys.path looks like this:
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
I have pip’ed everything in and when I run in the terminal with py -3.7 script.py it works and imports the modules however when run in touch I get the following output:
Traceback (most recent call last):
File "</project1/text1:op('/project1/text1').run()>", line 1
td.Error: File "/project1/text1", line 8
r = previousimport(*args, **kw)
File "C:\Python37\Lib\site-packages\google\cloud\speech.py", line 20
from google.cloud.speech_v1 import SpeechClient
r = previousimport(*args, **kw)
File "C:\Python37\Lib\site-packages\google\cloud\speech_v1\__init__.py", line 17
from google.cloud.speech_v1.gapic import speech_client
r = previousimport(*args, **kw)
File "C:\Python37\Lib\site-packages\google\cloud\speech_v1\gapic\speech_client.py", line 25
import google.api_core.gapic_v1.config
r = previousimport(*args, **kw)
File "C:\Python37\Lib\site-packages\google\api_core\gapic_v1\__init__.py", line 18
from google.api_core.gapic_v1 import config
r = previousimport(*args, **kw)
File "C:\Python37\Lib\site-packages\google\api_core\gapic_v1\config.py", line 23
import grpc
r = previousimport(*args, **kw)
File "C:\Python37\Lib\site-packages\grpc\__init__.py", line 23
from grpc._cython import cygrpc as _cygrpc
ImportError: cannot import name 'cygrpc' from 'grpc._cython' (C:\Python37\Lib\site-packages\grpc\_cython\__init__.py)
Results of run operation resulted in exception.
It is looking in the right place and it appears that everything is correct as it works with normal cmd python. Does anyone have any advice for debugging this or have any experience with something like this happening?
somewhere I read the lib is 32-bit, maybe confirm - TD will likely be trying to run 64-bit versions of python stuff, so might run into issues there.
I see you inserted C:\Python37\Lib\site-packages at top, I doubt this will make a difference in your case, but could try appending it to end of paths instead of at top.
it seems like the issue boils down to the import of grpc, namely this line: from grpc._cython import cygrpc as _cygrpc
Generally I like to cut all the fat when trouble shooting and just work on installing / importing that particular library into Touch from your external Python install.
When you get errors, try web searches around those errors and I think the results will be more targeted.
Thanks @lucasm. I have seen that link and have tried their suggestions and have tried the “ignore-installed” step and definitely have the right modules. I’m not sure it’s relevant as my code and an example program both execute fine, it is just in Touch that this error occurs which makes me think it is a touch specific path/execution problem. I’m pretty new to Touch and am not very well versed in its intricacies. I’ve tried including the module from my install of python as well as having pip’ed the modules directly into C:\Program Files\Derivative\TouchDesigner.2020.25380\bin\Lib\site-packages with the same import error both ways. I’ll try looking into the 32/64 bit idea.
If you haven’t yet, I recommend uninstalling the pip’ed version and installing the 64 bit pre-compiled binary from this page - curious to see if it works! https://www.lfd.uci.edu/~gohlke/pythonlibs/#grpcio
Thank you so much for your help @lucasm. Turns out it was a bit version error and I had mistakenly installed python 3.7 as 32 bit, hence why when I ran it in the terminal it worked but with Touch’s 64 bit python it did not. Uninstalled and reinstalled python and my dependencies and the import seems to work.