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
For Azure Function Apps with runtime stack as
Python
is limited toPython 3.9
.Before executing durable functions in visual studio code, I got the same kind of warning as below:
It states that it supports up to
Python 3.10
versions for executingdurable 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
:requirements.txt:
DurableHttpStarter function ->
init.py
:Output:
Triggered [localhost:7071/api/orchestrators/FunctionName]:
Check runtime status [localhost:7071/api/orchestrators/StatusQueryGetUri]:
Deployment successful:
Published to function app in portal:
Updated:
Reference: MSDoc
I had this exact issue today – upgrading python to 3.9 AND upgrading the azure function to runtime version ~4 cured the issue.
easiest short term solution is fix the version in your requirement.txt to version 1.1.6