.python_packages folder not deploying to Azure Python function

Greg Vance a 0 Reputation points
2024-07-29T17:32:26.6533333+00:00

I have an Azure function running Linux to which I'm deploying a Python function. All of my files deploy from my artifact to the Azure function except my .python_packages folder, which contains the libraries needed to make my function endpoint run. I've verified that the python_packages folder and its contents are in the zipped artifact. I'm deploying with the code snippet below:

- task: AzureCLI@2
  displayName: 'Deploy to Azure Linux Function App'
  inputs:
    azureSubscription: '{azSubscriptionName}'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: |
      # Variables
      $resourceGroupName = '{resourceGroupName}'
      $functionAppName = '{functionAppName}'
      $packagePath = '$(Pipeline.Workspace)/Folder_Path/AzureFunctionsArtifact/AzureFunctionsArtifact.zip'

      # Deploy the zip package directly to the function app
      az functionapp deployment source config-zip --resource-group $resourceGroupName --name $functionAppName --src $packagePath

      # Set the PYTHONPATH environment variable
      az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroupName --settings "PYTHONPATH=./.python_packages/lib/site-packages"

      # Restart the function app to apply changes
      az functionapp restart --name $functionAppName --resource-group $resourceGroupName
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,112 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 12,011 Reputation points
    2024-07-29T18:44:01.0066667+00:00

    Hello Greg Vance a,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    I understand that your .python_packages folder not deploying to Azure Python function

    Solution

    To resolve this issue and ensure that your Python packages are correctly deployed to your Azure Function, you will need to do the followings:

    1. In your function app's root directory, create a requirements.txt file. This file should list all the Python packages your function depends on. Make sure to include the necessary packages in this file.
    2. When deploying your function, ensure that the requirements.txt file is included in your deployment artifact (such as the zip package). This file tells Azure Functions which packages to install.
    3. Navigate to your function app in the Azure portal. Under the Platform features tab, select Advanced tools (Kudu). In the Kudu console, go to Debug console > CMD.
    4. In the CMD console, run the following command to install the Python packages from the requirements.txt file: pip install -r D:\home\site\wwwroot\requirements.txt
    5. After installing the packages, restart your function app to apply the changes: az functionapp restart --name <functionAppName> --resource-group <resourceGroupName>

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    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.