skip to Main Content

I have a durable app function running on versions 3.x written in pyhton 3.7 that worked fine from the last 1 year. After a new release due to a minor change in software I had to redeploy the function app via

func azure functionapp publish

When I try to run it locally using the Debug tool in VS Code I don’t get any error and everything works fine, but now when I run it in cloud (in az portal for instance) i get this error:

Result: Failure Exception: ImportError: cannot import name ‘FunctionRegister’ from ‘azure.functions’ (/azure-functions-host/workers/python/3.7/LINUX/X64/azure/functions/init.py). Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 318, in _handle__function_load_request func_request.metadata.entry_point) File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 42, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/loader.py", line 85, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "/home/site/wwwroot/ClientStarter/init.py", line 5, in import azure.durable_functions as df File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/durable_functions/init.py", line 14, in from .decorators import DFApp File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/durable_functions/decorators/init.py", line 4, in from .durable_app import DFApp File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/durable_functions/decorators/durable_app.py", line 10, in from azure.functions import FunctionRegister, TriggerApi, BindingApi, AuthLevel

I understood that there are some problems with module due to pyhton version and app version but I cannot go with 4.x, is there a way to still use 3.x and avoid the error?

Any help is appreciated

3

Answers


  1. For Azure Function Apps with runtime stack as Pythonis limited to Python 3.9.

    Before executing durable functions in visual studio code, I got the same kind of warning as below:

    enter image description here

    It states that it supports up to Python 3.10 versions for executing durable orchestrator functions in visual Studio Code, but not the most recent ones. (Python 3.11)

    Note: When working with Durable functions, version compatibility must be checked (Python). Otherwise, it will throw an "import errors".

    After meeting all of the prerequisites, I tried creating and executing the sample orchestrator, activity as well as client functions in my environment by installing dependencies and it worked successfully.

    Orchestrator-> init.py:

    import  logging
    import  json
    import  azure.functions  as  func
    import  azure.durable_functions  as  df
    def  orchestrator_function(context: df.DurableOrchestrationContext):
    result1 = yield  context.call_activity('Hello', "Tokyo")
    result2 = yield  context.call_activity('Hello', "Seattle")
    result3 = yield  context.call_activity('Hello', "London")
    return [result1, result2, result3]
    main = df.Orchestrator.create(orchestrator_function)
    

    requirements.txt:

    
    azure-functions
    azure-functions-durable
    

    DurableHttpStarter function -> init.py:

    
    import  logging
    import  azure.functions  as  func
    import  azure.durable_functions  as  df
    async  def  main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    instance_id = await  client.start_new(req.route_params["functionName"], None, None)
    logging.info(f"Started orchestration with ID = '{instance_id}'.")
    return  client.create_check_status_response(req, instance_id)
    

    Output:

    enter image description here

    Triggered [localhost:7071/api/orchestrators/FunctionName]:

    enter image description here

    Check runtime status [localhost:7071/api/orchestrators/StatusQueryGetUri]:

    enter image description here

    Deployment successful:

    enter image description here

    enter image description here

    Published to function app in portal:

    enter image description here

    Updated:

    enter image description here

    Reference: MSDoc

    Login or Signup to reply.
  2. I had this exact issue today – upgrading python to 3.9 AND upgrading the azure function to runtime version ~4 cured the issue.

    Login or Signup to reply.
  3. easiest short term solution is fix the version in your requirement.txt to version 1.1.6

    ... #other requirements
    azure-functions-durable==1.1.6
    ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search