[SOLVED] Python module error in touch but not in cmd

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:

C:\Program Files\Derivative\TouchDesigner.2020.25380\bin
C:\Program Files\Derivative\TouchDesigner.2020.25380\bin\python37.zip
C:\Program Files\Derivative\TouchDesigner.2020.25380\bin\DLLs
C:\Program Files\Derivative\TouchDesigner.2020.25380\bin\lib
C:\Program Files\Derivative\TouchDesigner.2020.25380\bin
C:/Program Files/Derivative/TouchDesigner.2020.25380/Config/Cmd

I have a script that just imports my modules

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?


I’m not sure if any of these ideas will be a solve, but worth checking out:

  1. See if any of these solutions work.

  2. 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.

  3. 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.

1 Like

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.

Thanks agian!

Ah did you pip install grpcio for that particular library?

1 Like

Yeah I installed with my requirements.txt:


So the file is there

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!

1 Like

thanks will try that now

what’s weird, is I was able to pip install that library the way you did, and import just fine. so there could be some other oddities.

1 Like

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.