Azure Function stuck using Python 3.9 despite configuring for Python 3.11 in runtime.txt and settings

BTCElectrician 0 Reputation points
2024-09-19T12:47:55.3666667+00:00

I’ve been trying to run an Azure Function using Python 3.11, but no matter what I do, the logs indicate that the function is running Python 3.9. I’ve gone through multiple deployment attempts and configurations but can’t seem to resolve this.

  1. I’m deploying my function as a ZIP package. I’ve confirmed that the runtime.txt is included and correctly set to python-3.11.
  2. I used unzip -l to confirm the structure of the ZIP file, and the runtime.txt is at the root level with the correct Python version specified.
  3. have set FUNCTIONS_WORKER_RUNTIME to python in the Azure Function App’s Configuration settings.
  4. I’ve checked the App Service Plan and confirmed it’s a Linux-based Consumption Plan (Y1), which supports Python 3.11.
  5. I’ve redeployed the function multiple times, each time ensuring the configuration and deployment package is correct.
  6. And Yes, I've checked my requirements.txt as well and made sure it was included in the my zip folder.

I don't know what else I could be doing wrong. Python is 3.11 on my local, on the portal, its everywhere, but where I need it. When I run a test curl via the portal I always a sudden 500 error and then this "Exception type: Microsoft.Azure.WebJobs.Host.FunctionInvocationException Exception message: Exception while executing function: Functions.vector_similarity_search

Exception: ModuleNotFoundError: No module named 'openai'. Cannot find module. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound.

Current sys.path: ['/tmp/functions\standby\wwwroot', '/home/site/wwwroot/.python_packages/lib/site-packages', '/azure-functions-host/workers/python/3.9/LINUX/X64', '/usr/local/lib/python39.zip', '/usr/local/lib/python3.9', '/usr/local/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/site-packages']

Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 479, in _handle__function_load_request func = loader.load_function( File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/site/wwwroot/vector_similarity_search/init.py", line 5, in

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,029 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,808 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 4,380 Reputation points Microsoft Employee
    2024-09-20T09:05:24.94+00:00

    Hello @BTCElectrician

    Let's try to troubleshoot this issue together.

    Firstly, it's good to know that Azure Functions currently supports Python versions 3.6, 3.7, 3.8, and 3.9. Python 3.11 is not yet supported, so that could be the reason why your function is defaulting to Python 3.9.

    If you have confirmed that your Azure Function App is running on a Linux-based Consumption Plan (Y1), which supports Python 3.11, then it's possible that the Python 3.11 runtime is not yet available on the worker that your function is running on.

    You can check the worker version by looking at the Current sys.path in the error message you provided.

    If the worker version is not 3.11, then you may need to wait until the worker is updated to support Python 3.11.

    Another thing to check is the FUNCTIONS_WORKER_RUNTIME setting in your Azure Function App's Configuration settings.

    Make sure that it is set to python and not python-3.9.

    This could be causing your function to default to Python 3.9.

    Lastly, the error message you provided indicates that there is a missing module named 'openai'. Make sure that this module is included in your requirements.txt file and that it is installed in your function's environment. You can check the installed packages by looking at the Current sys.path in the error message.


    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.