pythonazurepipazure-functions

azure function .python_packages missing


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?


Solution

  • 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.

    az functionapp deployment source config-zip \
      --resource-group <ResourceGroupName> \
      --name <FunctionAppName> \
      --src <PathToZipFile> \
      --build-remote
    

    This led to the requirements being installed upon deployment.