Skip to content

[BUG] Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage'. #819

@oliverchristen

Description

@oliverchristen

I've got an Azure Function app with two Azure Functions which use external packages (e.g. azure-storage-blob). In VSCode locally (even if it's a Windows box) this works fine. I have a CI/CD pipeline which deploys the function app to Azure using the recommended approach by Microsoft described here. The deployment works fine as well and the Azure Functions run successfully until I use external packages. When I do so, the following error occurs:

Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 275, in _handle__function_load_request func_request.metadata.entry_point) File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 34, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/site/wwwroot/GenerateReport/__init__.py", line 5, in <module> import azure.storage.blob as azureBlob 

I investigated all the things described here all the root causes do not seem to match:

  • Package exists in the zip file in .python_packages/lib/site-packages/azure/storage/blob (as it does locally)
  • Tag section in the WHEEL file contains Tag: py3-none-any which indicates it should run on linux
  • Classifier section in the METADATA file contains
    • Classifier: Programming Language :: Python :: 3.5
    • Classifier: Programming Language :: Python :: 3.6
    • Classifier: Programming Language :: Python :: 3.7
    • Classifier: Programming Language :: Python :: 3.8
    • Classifier: Programming Language :: Python :: 3.9
      so should be ok as well
  • There are no conflicts with other packages described here and I do not have the deprecated azure-storage package referenced in requirements.txt
  • The package supports linux I think: https://pypi.org/project/azure-storage-blob/12.7.1/ At least it's not mentioned that it isn't. But here I'm not sure.

The service plan of the Azure Function App is a Consumption plan (Y1).

What I also tried:

  • Use Azure Function Core Tools to deploy instead: func azure functionapp publish <app-name> --build-native-deps
    This leaded into the same error.
  • I tried to use the following versions of Python 3.6, 3.7, 3.8, 3.8 both for the pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt command and the LinuxFxVersion of the Azure Function App. There I used the notation Python|3.x
  • I removed the dependency to the package azure-storage-blob but left a dependency to another external package (fpdf2). The result was the following error: Result: Failure Exception: ModuleNotFoundError: No module named 'fpdf2'.
  • I locally renamed folder .venv\Lib\site-packages\azure to .venv\Lib\site-packages\azure_ which lead to the same error: Exception: ModuleNotFoundError: No module named 'azure.storage'.

So to me it looks like the azure function totally ignores the folder .python_packages/lib/site-packages/ somehow.

Perhaps this is related to the following issues which did not help in my case:
#477
#800

Investigative information

Please provide the following:
  • Timestamp: 2021-02-17 12:33:00.049
  • Function App name: bc-func-batch-analytics-dev
  • Function name(s) (as appropriate): GenerateReport
  • Core Tools version: 3.0.3233
  • Azure region: West Europe

Expected behavior

Provide a description of the expected behavior.

After deployment the Azure Function App should run the same way as it does locally.

Actual behavior

Provide a description of the actual behavior observed.

It runs locally but it doesn't on Azure because of the following error mentioned above:
Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage'.

Contents of the requirements.txt file:

Provide the requirements.txt file to help us find out module related issues.
azure-functions azure-storage-blob fpdf2 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions