Modules Not Found After Continuous Deployment from GitHub to Azure Function App

Masa_red 5 Reputation points
2025-01-15T04:24:43.2266667+00:00

I am using GitHub Actions for continuous deployment to my Azure Function App. According to the logs in GitHub Actions, all necessary Python modules are successfully installed, and the Python version matches both my local environment and the Azure runtime. However, when testing the function in the Azure portal, I encounter the following error:

ModuleNotFoundError: No module named '<module-name>'

What I Have Confirmed:

  1. The Python version is consistent across the local environment, GitHub Actions, and Azure Function App.
  2. All required modules are listed in requirements.txt, and they are successfully installed during the GitHub Actions workflow.
  3. The app setting SCM_DO_BUILD_DURING_DEPLOYMENT is set to 1 to enable remote builds.

Questions:

  1. What could be causing the deployed Azure Function App to fail in recognizing the required Python modules?
  2. Is it necessary to deploy the virtual environment (venv) along with the function, or should Azure handle the module installation automatically?
  3. Are there additional configurations or steps I should verify to ensure the required modules are properly recognized by Azure?

Additional Information:

  • The issue persists even after enabling remote builds (SCM_DO_BUILD_DURING_DEPLOYMENT).
  • The error consistently occurs when testing the function in the Azure portal.

Your guidance on resolving this issue would be greatly appreciated. Please let me know if you require further details.

Best regards, Questions:

  1. What could be causing the deployed Azure Function App to fail in recognizing the required Python modules?
  2. Is it necessary to deploy the virtual environment (venv) along with the function, or should Azure handle the module installation automatically?
  3. Are there additional configurations or steps I should verify to ensure the required modules are properly recognized by Azure?

Additional Information:

  • The issue persists even after enabling remote builds (SCM_DO_BUILD_DURING_DEPLOYMENT).
  • The error consistently occurs when testing the function in the Azure portal.

Your guidance on resolving this issue would be greatly appreciated. Please let me know if you require further details.

Best regards,

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,396 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Pinaki Ghatak 5,580 Reputation points Microsoft Employee
    2025-01-15T09:28:39.23+00:00

    Hello @Masa_red

    Based on the information you provided; it appears that the necessary Python modules are successfully installed during the GitHub Actions workflow and the Python version is consistent across all environments.

    To answer your questions:

    1. There could be several reasons why the deployed Azure Function App is failing to recognize the required Python modules. One possibility is that the modules are not installed in the correct location. Azure Functions requires modules to be installed in the site-packages directory, which is located in the root directory of the function app. You can check if the modules are installed in the correct location by navigating to the Kudu console for your function app and checking the contents of the site-packages directory.
    2. It is not necessary to deploy the virtual environment (venv) along with the function. Azure should handle the module installation automatically as long as the modules are listed in the requirements.txt file and are installed in the correct location.
    3. To ensure that the required modules are properly recognized by Azure, you can try the following steps:
      1. Double-check that the required modules are listed in the requirements.txt file and are spelled correctly.
      2. Make sure that the modules are installed in the correct location (site-packages directory).
      3. Check the logs in the Azure portal for any errors related to module installation or import.
      4. Try manually installing the modules in the Kudu console using pip to see if that resolves the issue.

    If none of these steps resolve the issue, it may be helpful to provide more details about the specific modules you are trying to install and any error messages you are seeing in the Azure portal logs.

    I hope this helps.

    0 comments No comments

  2. Juraj Vasek 0 Reputation points
    2025-01-21T23:09:19.66+00:00

    I faced the same issue: deployment from VS Code worked smoothly, but when deploying from GitHub using the default .yml workflow generated by the Azure Portal, none of the libraries from requirements.txt were installed. This resulted in ModuleNotFoundError, or an empty list of functions on Azure Portal.


    Solution 1 (with Remote Build):

    Forcing remote build with Oryx resolved the issue. While documentation suggests setting environmental variables, these settings are ignored or overwritten as false by @Azure/functions-action@v1 unless explicitly stated in the .yml file.

    	# ...
    
    	- name: 'Deploy to Azure Functions'
            uses: Azure/functions-action@v1
            id: deploy-to-function
            with:
              app-name: '...'
              slot-name: 'Production'
              package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
              publish-profile: ${{ ... }}
              scm-do-build-during-deployment: true # <--- ADDED THIS LINE
              enable-oryx-build: true              # <--- ADDED THIS LINE
    

    I tested this solution successfully on:

    • Consumption plan
    • Consumption Flex
    • App Service

    Solution 2 (without Remote Build):

    If I understand the documentation correctly, Linux Consumption plan apps cannot use this option. However, it works on the App Service plan (and possibly on Premium and Container plans, though I haven’t tested those). It does not work on Consumption and Consumption Flex plans.

    For some reason, the active venv does not persist between steps. Reactivating the venv before running pip install resolved the issue:

          # ...
    
          - name: Create and start virtual environment
            run: |
              python -m venv venv
              source venv/bin/activate
    
          - name: Install dependencies
            run: |                         # <--- EDITED THESE 2 LINES vvv
              source venv/bin/activate         
              pip install -r requirements.txt
    
          # Optional: Add step to run tests here
    
          - name: Zip artifact for deployment
            run: zip release.zip ./* -r
    
    	  # ...
    
    

    Key Insights:

    The Azure/functions-action@v1 assumes default values for scm-do-build-during-deployment and enable-oryx-build as false when nothing is provided. This is evident from the GitHub Actions logs:

    Run Azure/functions-action@v1
      with:
         app-name: 
         slot-name: Production
         package: .
         publish-profile: ***
         respect-pom-xml: false
         respect-funcignore: false
         scm-do-build-during-deployment: false
         enable-oryx-build: false
         remote-build: false
     env:
         AZURE_FUNCTIONAPP_PACKAGE_PATH: .
        
    Successfully parsed SCM credential from publish-profile format.
    Using SCM credential for authentication, GitHub Action will not perform resource validation.
    Successfully acquired app settings from function app (with SCM credential)!
    Will archive . into /home/runner/work/_temp/temp_web_package_5208750022074267.zip as function app content
    Will use Kudu https://<scmsite>/api/zipdeploy to deploy since publish-profile is detected.
    Setting SCM_DO_BUILD_DURING_DEPLOYMENT in Kudu container to false
    Update using context.kuduService.updateAppSettingViaKudu
    Response with status code 204
    App setting SCM_DO_BUILD_DURING_DEPLOYMENT propagated to Kudu container
    Setting ENABLE_ORYX_BUILD in Kudu container to false
    Update using context.kuduService.updateAppSettingViaKudu
    Response with status code 204
    App setting ENABLE_ORYX_BUILD propagated to Kudu container
    Package deployment using ZIP Deploy initiated.
    Deploy logs can be viewed at ...
    Successfully deployed web package to App Service.
    Restoring SCM_DO_BUILD_DURING_DEPLOYMENT in Kudu container to 1
    Response with status code 204
    Restoring ENABLE_ORYX_BUILD in Kudu container to 1
    Response with status code 204
    

    This process temporarily sets the environmental variables to false (or true), does not build, and then reverts to the original values.


    For ZIP deployment, the venv was originally empty, with no installed libraries like requests, msal, or azure-cosmos.

    User's image

    Here are the .yml files that worked for me:

    Also, the Azure workflow sample from Github should work as well.

    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.