I have an azure function app to which I am trying to deploy some python code to via zip upload through the CLI. I can get a hello world application to run but I cannot add external libraries. I added a requirements.txt in my root folder but this is not being picked up.
Many solutions and suggestions I found on the web revolve around pointing the python path to /home/site/wwwroot/.python_packages but when I ssh into the machine this path doesn’t even exist. I tried to put a venv in that path manually and installing the required packages but the function code still fails during import.
I used the portal to create a function app with python 3.11 on linux. Is this .python_packages folder still supposed to be there or did something change?
2
Answers
The reason the requirements.txt was not installing was that two flags were missing. In the environment variables of the function the following was missing:
SCM_DO_BUILD_DURING_DEPLOYMENT: true
. When using the zip upload command this variable will be set to false and in order to prevent that I needed to add the--build-remote
flag to my az cli command.This led to the requirements being installed upon deployment.
When I was zipping my files with my local environment which is
.venv
where all my additional packages are installed, function was not visible on azure even if deployment was successful.It was only working with default code. where no additional packages were available..
But this worked for me.
I installed packages in
.python_packages
using this command in locally.And then I zipped files with
.python_packages
, not.venv
.requirements.txt
:function_app.py
:OUTPUT