azure-functions-python-worker: Azure function python v2 with external packages HTTP Trigger not visible in Azure Portal after deployment
Refer this SO Thread and my answer - https://stackoverflow.com/questions/76458717/why-is-the-functions-runtime-not-finding-my-functions-when-i-import-certain-pack/76463210?noredirect=1#> The Azure python Function with V2 programming model including external packages and imports in function_app.py works locally, But when I deploy it in Azure the Function Trigger is not visible. If I deploy default HTTP Trigger with python v2 programming model, The trigger is visible after deployment. But not when i add custom imports in the function_app.py and requirements.txt. Refer this image - https://i.imgur.com/CjCnsY8.png but the function files are visible in app files like here- https://i.imgur.com/R3SZWcW.png . I tried the deployment with App service plan and consumption plan both, Still no luck. I also added AzureWebJobsFeatureFlags:EnableWorkerIndexing settings, I also tried to deploy this function as zip using azure cli zip command with required settings to deploy function as zip, I also tried to deploy it with function core tools func azure functionapp publish <function-app> command and also via VS code still no luck.
Investigative information
Please provide the following:
- Timestamp:
- Function App name: siliconfunc311
- Function name(s) (as appropriate): Http trigger pythonv2
- Core Tools version:4.0.5148
Repro steps
Provide the steps required to reproduce the problem:
Refer this SO thread and my answer- https://stackoverflow.com/questions/76458717/why-is-the-functions-runtime-not-finding-my-functions-when-i-import-certain-pack/76463210?noredirect=1#comment134830419_76463210
Expected behavior
Provide a description of the expected behavior.
after deployment HTTP trigger should be visible in Azure portal
Actual behavior
Provide a description of the actual behavior observed.
Function trigger is not visible in Functions section of Function tab but files are visible in app files
Known workarounds
Provide a description of any known workarounds.
Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.
numpy
pandas
opencv-python-headless
librosa
torch
torchaudio
torch-audiomentations
torchvision
azure-functions
Related information
Provide any related information
- Links to source
# function_app.py
import logging
import azure.functions as func
import numpy as np
import pandas as pd
import cv2
import librosa
import torch
import torchaudio
import torch_audiomentations
import torchvision
from azure.functions import HttpRequest
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.route(route="HttpTrigger")
def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
#code block with imported packages
arr = np.array([1, 2, 3])
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
image = cv2.imread('Screenshot (1).png')
audio_data, sample_rate = librosa.load('sample.wav.mp3')
tensor = torch.tensor([1, 2, 3])
transformed_tensor = torch_audiomentations.PitchShift(sample_rate=sample_rate, p=1.0)
torchvision.transforms.ToTensor()(image)
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}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 11
- Comments: 67 (5 by maintainers)
For whomever comes here in utter despair like I did; I’ve created a demo on when this issue occurs. With ‘issue’ I am pointing at the situation where a FunctionApp is successfully deployed but the Functions themselves don’t show up.
In essence, the problem lies in the code base (duh). If there is any error while loading your project, then Azure Functions will silence that and instead just won’t show any of the Functions in your Function app. It’s extremely hard to debug, as you have absolutely no idea what is going wrong. You can even get into the situation where it works locally, but not on Azure Functions. A possible cause for that is that you are testing it locally on a different OS (Windows for example) than where it will be deployed (Linux), and you are doing a *zip-deployment where the packages you zipped, contain Windows-specific binaries.
I am not saying this is specifically the case if you run in this issue. I am saying this is an example of an issue that is kept silence by Azure Functions so you can go down a completely unrelated rabbit hole.
The reproduction is here (https://github.com/JarroVGIT/azure-functions-python-v2-load-issue), with examples when it will and will not work. Hope it helps somebody save a day or two 😉
Why is this issue closed? Can it please be re-opened, this is still a pending issue which apparently lot of people are facing.
Thanks for looking into this.
Do we know if this problem is one multiple people are facing, and there is nothing we can do to deploy with Python v2 programming model?
This is high priority for us in the Functions team and we will have more information and a troubleshooting guide in the coming days - thank you all for your patience and feedback!
I was able to solve this by including all dependencies my app used in my
requirements.txtfile. I was able to solve it with the help of @saari-oj 's comment where they only had theimport azure.functions as funcas the only import.I then saw that my
requirements.txtfile only had that dependency listed. When I added my other project dependencies to the requirements file, it worked! My guess is, when deploying from VS code, the tool creates a .zip dir of the project, uploads it to Azure and Azure does a pip install from the requirements.txt.To update your project dependencies, make sure to update your requirements.txt file by running:
pip freeze > ./requirements.txtI’m using the v2 model, Python (v3.10) func app.
Hi All - I had exactly the same issue. Locally everything runs fine but when deploying to ASP I cannot see the functions.
After I removed ALL the imports (expect for azure.functions) from beginning of the file and added the imports under the method(s) that used them, then it started to work.
So DONT do it like this:
I am also facing the issue and just tried the method proposed by @robmitchellzone.
Code then looks something like that
Still, host log says: 2023-09-19T08:24:23.828 [Information] 1 functions found (Custom) 2023-09-19T08:24:23.828 [Information] 0 functions loaded
Code works fine when deploying from local.
What I am seeing is this log:
And the app function doesn’t appear in the functions tab, but the file do appear under app files. The exact same python code deployed to a different environment is working fine.
I’m experiencing a similar issue but with two differences:
One additional thing I’ve noticed when I’ve probed around in my portal is that Genie is reporting the following error:
That is followed by this error:
The key thing that strikes me as odd here is that it’s failing to import the package from /home/site/wwwroot/.python_pacakages/…
Looking in my storage account, the reason it’s failing is obvious - there’s no .python_packages file in wwwroot.
After liaising with the OP of this github issue on my own SO post, we’re using identical Azure Pipeline YAML definitions. The key thing is we’re both running from zip packages, rather than deploying the code directly so I wouldn’t expect there to be anything in wwwroot.
Since my function_app.py file imports a load of custom packages (which in turn import PIL), and does so before declaring the function, my thinking is that the imports are erroring about because Python should be looking for them in the package but is actually looking for them in the site root (working directory). Since they aren’t there, it errors out so never makes it as far as far as the function app declaration.
Just a guess but given the errors it would make sense.
What to do about that, however, I don’t know!
For now it looks like the two workarounds are:
I followed the first of these options and this resolved my issue.
Plus one.
It is very frustrating to debug issues that occur outside of the function definition.
For example, import errors, missing dependencies, or issues with the binding and trigger definitions.
We are essentially flying blind when trying to debug these problems.
Azure Functions should provide more access to logging that can lend a light to these issues.
I can confirm people’s observations that this is a dependency issue. My code has a dependency on another package I published privately where I forgot to list
jsonschemaas a requirement, as insetup(install_requires=[<jsonschema goes here>])insetup.py. Before fixing that issue I commented out parts of my project and reproduced the situations of finding / not finding the azure functions when publishing by importing / not importing the missing dependency to my code (I commented out the private dependency import to get rid of the transitive import).I also verified that jsonschema was not being built on the remote build.
After adding jsonschema to my current project’s requirements.txt file it worked, and of course, I also expect it to work when I fix the
install_requireson my privately published dependency.This explains why
pip freeze > ./requirements.txtsolves the symptom, but obviously the real issues are that:Thanks, @Soggywaters, this is what worked for me. Since that’s two people in this thread where this worked as a solution, I’m guessing this is a more common reason people are unable to deploy their functions.
All I have in my requirements.txt is azure-functions, and still getting it.
Very much useful, thank you for the insight @JarroVGIT. My python code would execute on the local host, but the function would never pop up in Azure, in spite of a successful deployment. Logs were basically limited to “Function Found: 1, Function Loaded: 0”. After hours of troubleshooting, I simply realized that I’d set psycopg2 as a requirement instead of psycopg2-binary (pg engine driver, and of course postgres was not readily available as a binary on the Service Plan). It is highly confusing for a dev as Azure reported the Function deployment as successful, and not a single error or warning was logged.
Correct. I ran I to a smililar issue in a python v1 app last year. I forgot that I had to add that dependency again. Apparently v4 of the protobuf package had breaking changes.
@shahztechfarm, I had variables declared above my function definition in my
blueprint.pyfile. Moving those statements to within the function allowed Azure to detect the function when deployed to the cloud.I am also experiencing the issue. Local running works fine but deployment using VSCode and the CLI result in no functions being shown in the Azure Portal with no error messages being thrown.
I am having the same issue with my functions no showing/loading. Everything works locally & debugging but when pipelines or vscode deploys to the function it succeeds but never shows any functions.
I had a similar issue, my Azure Function worked perfectly in local testing. Deployment was succesful, but no triggers were shown. I could not find any logs showing any errors at all.
I downgraded to the v1 python worker based on the discussion in this thread. Using the v1 worker, the trigger was created, but I could see it generated an error when trying to import the
psycopg2package, changing the requirements.txt to usepsycopg2-binaryfixed this issue. Retrying the v2 python worker using thepsycopg2-binarypackage worked and the trigger showed up succesfully. I think this is similar to the issue @VirajVaitha123 was experiencing.It appears the v2 worker doesn’t show an error message and doesn’t create the trigger where the v1 worker does.
Can you reproduce it on your end with the code in the question? with python function v2? The trigger won’t be visible in the portal despite all the solutions in v2. It works in v1
Did this problem start recently?
I had a v2 programming function app deployed that was working fine, however last night i made some changes and I can no longer see the functions. I’ve tried everything and attempting to revert to the old code but I can’t seem to see what is different.
Maybe Azure have made some changes that have impacted us?