question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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: https://github.com/Azure/azure-functions-python-worker/issues/477 https://github.com/Azure/azure-functions-python-worker/issues/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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
oliverchristencommented, Feb 18, 2021

I found the reason why it was not working. I was just missing to set environment variable FUNCTIONS_WORKER_RUNTIME to python.

It’s just weird to me that it works fine without external packages even without this environment variable.

Hope this helps someone.

0reactions
caffinitcommented, Jan 25, 2022

@abhiraj1289 Thank you for the reply! Your comments helped me get past this exception.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'azure.storage'. Azure Function
The import statement is failing. import azure.functions as func from azure.storage.blob import generate_container_sas. with. Exception: ...
Read more >
No module named 'azure-storage-blob' – Finxter
How to Fix “ModuleNotFoundError: No module named 'azure-storage-blob'” in PyCharm · Open File > Settings > Project from the PyCharm menu. · Select...
Read more >
No module named 'azure.storage.blob' - Microsoft Q&A
Azure Functions Locally ModuleNotFoundError: No module named 'azure.storage.blob' ... both in VS code and cmd I get the following error:.
Read more >
ModuleNotFoundError: No module named 'azure-storage'
After the installation of azure-storage python library, ModuleNotFoundError: No module named 'azure-storage' error will be solved. Thanks. Post Answer.
Read more >
azure-storage-blob - PyPI
Microsoft Azure Blob Storage Client Library for Python. ... To get the specific error code of the exception, use the error_code attribute, i.e, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found