Requirements.txt not being installed through package deployment URL
Hi all, hopefully someone here could guide me in the right direction with this because I am a bit lost. Details: Python version: Tried 3.9 and 3.11 Python model: Tried both v1 and new v2 models Runtime OS: Linux Way of deployment: Bicep Func app deployment: Install with SAS URL through WEBSITE_RUN_FROM_PACKAGE: <URL> (this works)
So as the title says, the issue is that my requirements.txt is being ignored. I am using the following env variables for this process: { name: 'WEBSITE_RUN_FROM_PACKAGE' value: zipPackageUrlWithSas } { name: 'ENABLE_ORYX_BUILD' value: 'true' } { name: 'SCM_DO_BUILD_DURING_DEPLOYMENT' value: 'true' }
I can redeploy through bicep, the func app restarts, I can change the default code and verify execution runs the updated code. As long as I do not add extra packages in the requirements.txt. When I add (for example) requests, it stops working.
Everything seems to work but when I run the code with extra requirements on V1 Python Model it throws HTTP 500, and when I deploy through V2 Python model it throws HTTP 404. I verified through app insights that it is indeed throwing module not found error.
However, when I go to the "App Files" section in Azure Portal, I see the file is just there, it contains my requirements.txt, the requirements.txt contains requests, but it's not working.
I even tried adding a .python-packages directory to my .zip (even though that would be highly undesirable) but it does not work anyway.
Does anyone know what I can do here?
EDIT:
Actually after investigating further into how people deploy through DevOps pipelines, they run the requirements.txt file from a former step in DevOps to install the requirements to a specific location (the .python_packages/ dir). I manually ran the script pip install -r requirements.txt -t .python_packages/lib/site-packages and rezipped all files. Then I added that .zip to the blob storage and reran Bicep making it work.
Now onto automating this. Issue can be closed but might be relevant info for others to use in the future.
Actually, I am running into more issues here. When I try to use func pack on function apps that contain packages that depend on cffi (I believe azure-identity and azure-keyvault-secrets) it throws the following error:
ERROR: cannot install cffi-1.16.0 dependency: binary dependencies without wheels are not supported when building locally. Use the "--build remote" option to build dependencies on the Azure Functions build server, or "--build-native-deps" option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish
Things I tried:
- Remote building
- Docker building
- Local building Python 3.11 Windows
- Local building Python 3.9 Windows
- Local building 3.10 Macbook
All these options throw the same error. When I run the command in my original post (install -r requirements.txt -t .python_packages/lib/site-packages) and then manually zip the files, I can deploy them to my function app but then it crashes when a function is triggered. Cannot find solutions on google either.
Could anyone help with this?
Hello @ogiel, Thanks for the detailed explanation.
The root issue is that when deploying via WEBSITE_RUN_FROM_PACKAGE, Azure doesn’t automatically install packages listed in requirements.txt. This automatic installation only occurs when using deployment methods that trigger a build process, such as remote builds with Azure Functions Core Tools or Oryx in DevOps pipelines. Since you’re deploying a pre-packaged ZIP file, you need to ensure all dependencies are included in the package. Here’s how you can do it:
- Use a Linux-based environment to match Azure’s runtime.
- Install dependencies locally into the .python_packages/lib/site-packages directory: pip install -r requirements.txt -t .python_packages/lib/site-packages
- Package your function app, ensuring the .python_packages directory is included: zip -r functionapp.zip .
- Deploy the ZIP package to Azure via Blob Storage and reference it using the WEBSITE_RUN_FROM_PACKAGE setting.
For more detailed information, you can refer to this documentation: Bring dependencies and third-party libraries to Azure Functions.
Closing the issue as there is no feedback.