pythonazure-functionsdependencies

module not found 'azure-data' when deploying azure function, works locally


I am building a python function. When I run it locally, everything works as expected. When I try to deploy it (using GitHub Actions), the deployment is successful, but the function can not be started, because it throws an error.

As you can see in the following picture, the build process works fine and I can run the function_app.py in the generated folder, when extracting the zip.

build Action on GitHub Actions

However, when I look into the azure function logs, I see that the function has been started with 0 routes mapped. Here are the logs from the function startup:

4/11/2025, 2:42:50.361 PM   Job host started    1
4/11/2025, 2:42:49.565 PM   Initializing Warmup Extension.  1
4/11/2025, 2:42:49.571 PM   Initializing Host. OperationId: '1393eee4-b797-4b1e-ba9f-7863e0b9f902'. 1
4/11/2025, 2:42:49.571 PM   Host initialization: ConsecutiveErrors=0, StartupCount=3, OperationId=1393eee4-b797-4b1e-ba9f-7863e0b9f902  1
4/11/2025, 2:42:49.575 PM   Traceback (most recent call last):  1
4/11/2025, 2:42:49.575 PM   File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call   1
4/11/2025, 2:42:49.575 PM   return func(*args, **kwargs)    1
4/11/2025, 2:42:49.575 PM   ^^^^^^^^^^^^^^^^^^^^^   1
4/11/2025, 2:42:49.575 PM   File "/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py", line 244, in index_function_app    1
4/11/2025, 2:42:49.575 PM   imported_module = importlib.import_module(module_name)  1
4/11/2025, 2:42:49.575 PM   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    1
4/11/2025, 2:42:49.575 PM   File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module  1
4/11/2025, 2:42:49.575 PM   return _bootstrap._gcd_import(name[level:], package, level) 1
4/11/2025, 2:42:49.575 PM   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    1
4/11/2025, 2:42:49.575 PM   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import 1
4/11/2025, 2:42:49.575 PM   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load  1
4/11/2025, 2:42:49.575 PM   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked 1
4/11/2025, 2:42:49.575 PM   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked   1
4/11/2025, 2:42:49.575 PM   File "<frozen importlib._bootstrap_external>", line 940, in exec_module 1
4/11/2025, 2:42:49.575 PM   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed    1
4/11/2025, 2:42:49.575 PM   File "/home/site/wwwroot/function_app.py", line 4, in <module>  1
4/11/2025, 2:42:49.575 PM   from azure.data.tables import TableClient, TableServiceClient   1
4/11/2025, 2:42:49.575 PM   ModuleNotFoundError: No module named 'azure.data'   3

What's the problem here? The function does start up, but gets caught on line 4 of the function_app.py - here's the line in code:

from azure.data.tables import TableClient, TableServiceClient

Really appreciate any insights here

PS: of course the dependency is listed in requirements.txt in case you were wondering - that's why it also runs anywhere else but when deployed.

Edit: The workflow file is this:

# Docs for the Azure Web Apps Deploy action: 

https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions

name: Deploy 

on:
  push:
    branches:
      - test
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: './api' # set this to the path to your web app project, defaults to the repository root
  PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8)
  AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
  AZURE_COSMOS_CONNECTION_STRING: ${{ secrets.AZURE_COSMOS_CONNECTION_STRING }}

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read #This is required for actions/checkout

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Copy /shared to /api
        run: cp -r ./shared ./api/

      - name: Create and start virtual environment
        run: |
          python3 -m venv venv
          source venv/bin/activate
      - name: Install dependencies (api)
        run: pip3 install -r ./api/requirements.txt

      # Optional: Add step to run tests here
      - name: Test function app
        run: python3 ./api/function_app.py
      # end of tests

      - name: Zip artifact for deployment
        run: zip release.zip ./api/* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: python-app
          path: |
            release.zip
  deploy:
    runs-on: ubuntu-latest
    needs: build
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip     
        
      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'my_app'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_XXXXXXXX }}
          sku: 'flexconsumption'
    

Solution

  • I got it to work on a FLEX Consumption plan. I deployed the exact same zip file (using azure cli) to two functions, one one FLEX and one on normal consumption plan. On the Consumption plan it still produces the original error, module not found, while on the flex plan it deploys successfully. must be a bug