Can't import name 'cygrpc' from 'grpc._cython

929 views Asked by At

I'm trying to locally test a function i've written, but keep getting the error "cannot import name 'cygrpc' from 'grpc._cython" which causes attempts to run the function to fail

I've made sure i'm running python 3.9 for compatibility, and the most recent version of azure functions core tools, as specified on the microsoft troubleshooting web page. Does anyone know of another work around for this?

2

There are 2 answers

0
Jahnavi On

Can't import name 'cygrpc' from 'grpc._cython: -

According to the MSDoc, "can't import name 'cygrpc'" error occurs when there is a mismatch in the configuration between Python interpreter and Os architecture.

Verify the bitness of Python interpreter using below command.

py -c 'import platform; print(platform.architecture()[0])'

enter image description here

And this error might also be caused due to the Python version incompatibility with Azure functions worker as Azure functions worker accepts Python 3.6, 3.7, 3.8, 3.9only. Refer above given MS Doc for more detailed information.

Check Python version using below command:

py --version

To resolve this issue, try using py -m pip install grpcio to import the package instead grpc package. Recently the versions of grpc python library got renamed as grpcio to avoid potential naming conflicts.

Note: Make sure that the python version is 3.7 if you are using this workaround.

enter image description here

0
MRTN On

On Windows - I had successfully resolved the issue by changing the "defaultRuntimeVersion" to "3.11" in the file worker.config.json that could be found in the folder \Program Files\Microsoft\Azure Functions Core Tools\workers\python. This fix worked for az core tool v 4.0.5571