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.

No module named azure.storage

See original GitHub issue

Hello everyone,

I have written python code to access my blob storage working well locally from my PyCharm with Python 3.6.8.

import json
from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name='XX', account_key='YY')
block_blob_service.get_blob_to_path('activities', 'remi', 'remi.json')

with open('remi.json') as json_file:
    activitiesAsStr = json_file.read().replace('','',1)
    activities = json.loads(activitiesAsStr)
    print(activities)

If I move this code into an Azure function using the core tools:

import logging
import json
import azure.functions as func
import pathlib
from azure.storage.blob import BlockBlobService

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    block_blob_service = BlockBlobService(account_name='ACCOUNT', account_key='KEY')
    block_blob_service.get_blob_to_path('activities', 'remi', 'remi.json')
    with open(pathlib.Path(__file__).parent / 'remi.json') as json_file:
        str = json_file.read().replace('','',1)
        headers  = {
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "Get, Post, Options"
        }
        return func.HttpResponse(str, headers=headers)

and launch it as debug from visual studio code or deploy it to the cloud and it no longer works.

The python interpreter points to the same python install that my standalone code that works outside of azure function.

Logs

Executed ‘Functions.ActivitiesFromBlobStorage’ (Failed, Id=3b00374c-488c-4e1c-9552-c20a3e9b8abb) [7/2/2019 11:54:12 AM] System.Private.CoreLib: Exception while executing function: Functions.ActivitiesFromBlobStorage. System.Private.CoreLib: Result: Failure Exception: ModuleNotFoundError: No module named ‘azure.storage’ Stack: File “C:\Users\remid\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\dispatcher.py”, line 230, in handle__function_load_request func_request.metadata.entry_point) File “C:\Users\remid\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\deps\azure\functions_worker\loader.py”, line 66, in load_function mod = importlib.import_module(fullmodname) File "C:\Program Files\Python36\lib\importlib_init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “<frozen importlib._bootstrap>”, line 994, in _gcd_import File “<frozen importlib._bootstrap>”, line 971, in _find_and_load File “<frozen importlib._bootstrap>”, line 941, in _find_and_load_unlocked File “<frozen importlib._bootstrap>”, line 219, in _call_with_frames_removed File “<frozen importlib._bootstrap>”, line 994, in _gcd_import File “<frozen importlib._bootstrap>”, line 971, in _find_and_load File “<frozen importlib._bootstrap>”, line 955, in _find_and_load_unlocked File “<frozen importlib._bootstrap>”, line 665, in _load_unlocked File “<frozen importlib._bootstrap_external>”, line 678, in exec_module File “<frozen importlib._bootstrap>”, line 219, in call_with_frames_removed File "ActivitiesFromBlobStorage_init.py", line 5, in <module> from azure.storage.blob import BlockBlobService Here is my local settings

Python 3.6.8 with the following packages azure==4.0.0 azure-applicationinsights==0.1.0 azure-batch==4.1.3 azure-common==1.1.23 azure-cosmosdb-nspkg==2.0.2 azure-cosmosdb-table==1.0.5 azure-datalake-store==0.0.46 azure-eventgrid==1.3.0 azure-functions==1.0.0b5 azure-graphrbac==0.40.0 azure-keyvault==1.1.0 azure-loganalytics==0.1.0 azure-mgmt==4.0.0 azure-mgmt-advisor==1.0.1 azure-mgmt-applicationinsights==0.1.1 azure-mgmt-authorization==0.50.0 azure-mgmt-batch==5.0.1 azure-mgmt-batchai==2.0.0 azure-mgmt-billing==0.2.0 azure-mgmt-cdn==3.1.0 azure-mgmt-cognitiveservices==3.0.0 azure-mgmt-commerce==1.0.1 azure-mgmt-compute==4.6.2 azure-mgmt-consumption==2.0.0 azure-mgmt-containerinstance==1.5.0 azure-mgmt-containerregistry==2.8.0 azure-mgmt-containerservice==4.4.0 azure-mgmt-cosmosdb==0.4.1 azure-mgmt-datafactory==0.6.0 azure-mgmt-datalake-analytics==0.6.0 azure-mgmt-datalake-nspkg==3.0.1 azure-mgmt-datalake-store==0.5.0 azure-mgmt-datamigration==1.0.0 azure-mgmt-devspaces==0.1.0 azure-mgmt-devtestlabs==2.2.0 azure-mgmt-dns==2.1.0 azure-mgmt-eventgrid==1.0.0 azure-mgmt-eventhub==2.6.0 azure-mgmt-hanaonazure==0.1.1 azure-mgmt-iotcentral==0.1.0 azure-mgmt-iothub==0.5.0 azure-mgmt-iothubprovisioningservices==0.2.0 azure-mgmt-keyvault==1.1.0 azure-mgmt-loganalytics==0.2.0 azure-mgmt-logic==3.0.0 azure-mgmt-machinelearningcompute==0.4.1 azure-mgmt-managementgroups==0.1.0 azure-mgmt-managementpartner==0.1.1 azure-mgmt-maps==0.1.0 azure-mgmt-marketplaceordering==0.1.0 azure-mgmt-media==1.0.0 azure-mgmt-monitor==0.5.2 azure-mgmt-msi==0.2.0 azure-mgmt-network==2.7.0 azure-mgmt-notificationhubs==2.1.0 azure-mgmt-nspkg==3.0.2 azure-mgmt-policyinsights==0.1.0 azure-mgmt-powerbiembedded==2.0.0 azure-mgmt-rdbms==1.9.0 azure-mgmt-recoveryservices==0.3.0 azure-mgmt-recoveryservicesbackup==0.3.0 azure-mgmt-redis==5.0.0 azure-mgmt-relay==0.1.0 azure-mgmt-reservations==0.2.1 azure-mgmt-resource==2.2.0 azure-mgmt-scheduler==2.0.0 azure-mgmt-search==2.1.0 azure-mgmt-servicebus==0.5.3 azure-mgmt-servicefabric==0.2.0 azure-mgmt-signalr==0.1.1 azure-mgmt-sql==0.9.1 azure-mgmt-storage==2.0.0 azure-mgmt-subscription==0.2.0 azure-mgmt-trafficmanager==0.50.0 azure-mgmt-web==0.35.0 azure-nspkg==3.0.2 azure-servicebus==0.21.1 azure-servicefabric==6.3.0.0 azure-servicemanagement-legacy==0.20.6 azure-storage==0.36.0 azure-storage-blob==1.5.0 azure-storage-common==1.4.2 azure-storage-file==1.4.0 azure-storage-queue==1.4.0

Thanks for your help!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:38 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
abhiraj1289commented, Oct 21, 2021

Hi @marcosjur, You don’t need virtual environment to execute azure function in cloud So instead of above commands, use the below one
pip install --target=“$(System.DefaultWorkingDirectory)/.python_packages/lib/site-packages” -r requirements.txt

3reactions
larryfeng2008commented, Jun 20, 2020

I’m using python 3.8 and have the same issue. I have a Azure http function running well locally, but didn’t work when deploy to cloud. ModuleNotFoundError: No module named ‘azure.storage’. Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File “/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py”, line 259, in _handle__function_load_request func_request.metadata.entry_point) File “/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/utils/wrappers.py”, line 31, in call raise extend_exception_message(e, message) File “/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/utils/wrappers.py”, line 29, in call return func(*args, **kwargs) File “/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/loader.py”, line 73, in load_function mod = importlib.import_module(fullmodname) File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “/home/site/wwwroot/poc1/init.py”, line 4, in <module> from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named azure.storage.blob (when doing syncdb)
As I know, this issue is due to the version of azure storage client library for python.The old version has only one blobservice.py...
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'; 'azure' is not a package ...
from azure.storage.blob import BlobClient ModuleNotFoundError: No module named 'azure.storage'; 'azure' is not a package. To Reproduce
Read more >
No module named 'azure.storage.blob' - Microsoft Q&A
Im writing in VS Code and python, on a windows computer. I'm trying to create an Azure function with Blob Trigger. When I...
Read more >
ModuleNotFoundError: No module named 'azure-storage'
Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'azure-storage' How to remove the Modu.
Read more >

github_iconTop Related Medium Post

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