Azure-functions-core-tools: ImportError: cannot import name 'cygrpc' - when using 32-bit python

Created on 30 Jul 2019  路  15Comments  路  Source: Azure/azure-functions-core-tools

func --version: 2.7.1480
Windows: 10
VScode: 1.36.1
Python (Anaconda): 3.6.8
Region: Europe

I am trying to create a simple Python function in VScode and would like to test it locally.
However, when running func host start, I get the following error:

[30-07-2019 15:36:29] Starting language worker process:python  "...\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\worker.py" --host 127.0.0.1 --port 63313 --workerId a1454793-25c8-4277-9a29-867ec0551e05 --requestId 2bcba29b-78ed-429f-9bdb-794a022c08b3 --grpcMaxMessageLength 134217728
[30-07-2019 15:36:29] python process with Id=13728 started
[30-07-2019 15:36:29] Traceback (most recent call last):
[30-07-2019 15:36:29]   File "...\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\worker.py", line 1, in <module>
[30-07-2019 15:36:29]     from azure.functions_worker import main
[30-07-2019 15:36:29]   File "...\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\main.py", line 7, in <module>
[30-07-2019 15:36:29]     from . import dispatcher
[30-07-2019 15:36:29]   File "...\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\dispatcher.py", line 14, in <module>
[30-07-2019 15:36:29]     import grpc
[30-07-2019 15:36:29]   File "...\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\grpc\__init__.py", line 23, in <module>
[30-07-2019 15:36:29]     from grpc._cython import cygrpc as _cygrpc
[30-07-2019 15:36:29] ImportError: cannot import name 'cygrpc'

_cpython directory contains the following:

__init__.py
__pycache__/
_credentials/
_cygrpc/
cygrpc.cp36-win_amd64.pyd*

My function is a simple BlobTrigger:

import logging
import azure.functions as func

def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

Thanks!

Most helpful comment

Issue resolved by using 64-bit python. I did the same as @jameseleach.

Thank you for your help @maiqbal11! It would be great, if an error was given when using 32-bit python. Perhaps it should also be noted in the documentation to make it more clear.

All 15 comments

Windows: 10
VScode: 1.36.1 (user setup)
Python: 3.6.8 (3.6.8150.0)
Function is not yet published to Azure

I'm having the same issue. Originally I had azure-function-core-tools installed using Chocolatey but I've uninstalled it using Chocolatey and installed it using npm. I'm receiving the same error as @kajwanr.

The contents of my _cython folder are as follows:

Mode   Length  Name
----   ------  ----
d-----         ..\grpc\_cython\_credentials
d-----         ..\grpc\_cython\_cygrpc
d-----         ..\grpc\_cython\__pycache__
-a---- 3327488 ..\grpc\_cython\cygrpc.cp36-win_amd64.pyd
-a---- 590     ..\grpc\_cython\__init__.py
-a---- 283159  ..\grpc\_cython\_credentials\roots.pem
-a---- 590     ..\grpc\_cython\_cygrpc\__init__.py
-a---- 206     ..\grpc\_cython\__pycache__\__init__.cpython-36.pyc

My function is the default:

import logging

import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello {name}!")
    else:
        return func.HttpResponse(
             "Please pass a name on the query string or in the request body",
             status_code=400
        )

/cc @maiqbal11

@kajwanr, @jameseleach, could you check your Python version to see if it is 32-bit or 64-bit? The library in question is built for 64-bit Python and will not work with 32-bit.

where should that error be handled?

I believe it should be part of the core tools since that is where we package all the dependencies. We can surface a warning if we detect a user running a 32-bit version of Python. The error itself will get thrown if we try to import in the Python interpreter so we would have to surface something before that happens.

Why can't the python worker or the runtime handle that?

I do think we should re-think having a strong dependency on a specific Python version and architecture.
https://github.com/Azure/azure-functions-python-worker/issues/450

Users should also be able to mitigate this issue by performing a pip install azure-functions-worker which will install the dependencies for their own architecture.

Why can't the python worker or the runtime handle that?

The worker doesn't install any dependencies itself. It only uses them. The alternatives are to install the required dependencies before we run the local debugging flow (which is what we used to do) or we can package the worker dependencies for different platforms/architectures with the host (which is a discussion that we had with @pragnagopa as that would require some work to update worker.config.json to handle this). Happy to discuss this more offline as well.

The users shouldn't be installing those packages. They are packaged with the core-tools. The worker is the component loading those packages. Pushing all error handling to artificial checks in the tooling is not the right way of doing everything

@maiqbal11 I was using 32 bit Python. I have uninstalled it and installed 64 bit Python 3.6.8. I received an error when trying to run using the pre-existing virtual environment I had created with the 32 bit python install so I deleted it and recreated it. I don't have the 'py' command but was able to create the virtual environment by running python -m venv .venv

I then initialized a new function with the func init command, created a function with func new and was able to successfully start it with func host start.

In my case it was definitely an issue with running 32 bit python. Thank you for the assistance!

Issue resolved by using 64-bit python. I did the same as @jameseleach.

Thank you for your help @maiqbal11! It would be great, if an error was given when using 32-bit python. Perhaps it should also be noted in the documentation to make it more clear.

Lets leave it open until we sort out the error message and docs

Currently we do not have a way to configure python version, bitness for the worker. This will be addressed as part of supporting multiple versions. Tracking issue: https://github.com/Azure/azure-functions-core-tools/issues/1428

Note: Udpating core tools is just one part. We will have related work items in host - to select the right version of the worker and in worker - to package worker for different flavors we support.

@kulkarnisonia16, can we add this to our docs -- that we currently need users to have Python 3.6 __64__ __bit__

Closing this as fixed, if you face the same issues again please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SteveALee picture SteveALee  路  4Comments

MattHoneycutt picture MattHoneycutt  路  4Comments

brandonh-msft picture brandonh-msft  路  4Comments

buragc picture buragc  路  6Comments

nzthiago picture nzthiago  路  3Comments