Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
336 stars 104 forks source link

No module named azure.storage #477

Closed remster85 closed 5 years ago

remster85 commented 5 years ago

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 _handlefunction_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 "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 941, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "ActivitiesFromBlobStorage\init__.py", line 5, in 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!

maiqbal11 commented 5 years ago

@remster85, did you try installing the requirements using pip install -r requirements.txt for local development? Could you also share the error message you are receiving when publishing/published to the cloud?

remster85 commented 5 years ago

@maiqbal11 thanks for responding.

I have not tried that, where is the requirements file for my dependencies? https://pypi.org/project/azure-storage-blob

I have a 500 internal server error and the cloud log is the following

Result: Failure
Exception: ModuleNotFoundError: No module named 'azure.storage'
Stack:   File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 230, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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 "<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 "/home/site/wwwroot/ActivitiesFromBlobStorage/__init__.py", line 5, in <module>
    from azure.storage.blob import BlockBlobService
maiqbal11 commented 5 years ago

You can initialize a requirements.txt file in the root of the function app and include the dependencies that you need in it:

azure==4.0.0
azure-applicationinsights==0.1.0
azure-batch==4.1.3
azure-common==1.1.23
...

Once that is done, you should call pip install -r requirements.txt (in a virtual environment or globally). This should resolve the import issues.

remster85 commented 5 years ago

Thank you.

requirements.txt

azure-storage-blob==1.5.0

Error faced cannot install cryptography-2.6.1 dependency: binary dependencies without wheels are not supported. Use the --build-native-deps option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish

I will look into it. Same problem as https://github.com/Azure/azure-storage-python/issues/585

doublepithre commented 5 years ago

Same error, work perfectly on local environment but when deployed to FunctionApp, I notice the following error

Exception while executing function: Functions.HttpTrigger <--- Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage' 
Stack: File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", 
line 230, in _handle__function_load_request func_request.metadata.entry_point) 
File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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 "<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 "/home/site/wwwroot/HttpTrigger/__init__.py", line 6, in <module> 
from azure.storage.blob import BlockBlobService
LogLevel    Error
FormattedMessage    Executed 'Functions.HttpTrigger' (Failed, Id=a886d212-59e8-4c85-8828-82fa3e602f1d)
Category    Function.HttpTrigger
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.HttpTrigger ---> Microsoft.Azure.WebJobs.Script.Rpc.RpcException: Result: Failure
Exception: ModuleNotFoundError: No module named 'azure.storage'
Stack:   File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 230, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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 "<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 "/home/site/wwwroot/HttpTrigger/__init__.py", line 6, in <module>
    from azure.storage.blob import BlockBlobService
....

requirements.txt

asn1crypto==0.24.0
astroid==2.2.5
azure-common==1.1.23
azure-functions==1.0.0b5
azure-storage-blob==2.0.1
azure-storage-common==2.0.0
certifi==2019.6.16
cffi==1.12.3
chardet==3.0.4
cryptography==2.7
idna==2.8
isort==4.3.21
lazy-object-proxy==1.4.1
mccabe==0.6.1
numpy==1.16.4
pandas==0.24.2
pkg-resources==0.0.0
pycparser==2.19
pylint==2.3.1
python-dateutil==2.8.0
pytz==2019.1
requests==2.22.0
six==1.12.0
typed-ast==1.4.0
urllib3==1.25.3
wrapt==1.11.2
doublepithre commented 5 years ago

I tried deploying the app using the following command instead of VSCode extension

func azure functionapp publish yourFunctionAppName --build-native-deps

And it worked!!

remster85 commented 5 years ago

I decided to write this code using DotNet instead since I do not have docker on my personal windows laptop.

Error was "Got permission denied trying to run docker. Make sure the user you are running the cli from is in docker group or is root"

I am also unable to download the python function app content from the portal (404 error), one idea being to include the dependency within a zip pushed to azure.

Here is the sample in DotNet.

takumats commented 5 years ago

I'm not sure this my experience helps you.

We faced same error on our environment. After some investigation, we found followings.

This function had worked fine for a long time (over 1 month) on EastAsia region, but suddenly we got error around 2 days ago.

Additional info: We have already used --build-native-deps option to deploy it.

Hope this helps you. Thank you.

shanjin14 commented 5 years ago

Hello , I got the same issue after deploy Azure Functionon EastAsia region. The same function has been running for close to 2 weeks+ with no issue and broke around 2 days back.

Any idea how to fix this issue ? The code runs fine locally with no issue.

Error Message in Azure Function Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage' Stack: File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 237, in _handle__function_load_request func_request.metadata.entry_point) File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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/adffunction/init.py", line 11, in from azure.storage.blob import BlockBlobService

my requirement.txt: asn1crypto==0.24.0 astroid==2.2.5 azure-common==1.1.23 azure-functions==1.0.0b5 azure-functions-worker==1.0.0b9 azure-nspkg==3.0.2 azure-storage==0.36.0 azure-storage-common==2.0.0 certifi==2019.6.16 cffi==1.12.3 chardet==3.0.4 colorama==0.4.1 cryptography==2.7 grpcio==1.20.1 grpcio-tools==1.20.1 idna==2.8 isort==4.3.21 lazy-object-proxy==1.4.1 mccabe==0.6.1 protobuf==3.9.0 psycopg2-binary==2.8.3 pycparser==2.19 pylint==2.3.1 python-dateutil==2.8.0 requests==2.22.0 six==1.12.0 typed-ast==1.4.0 unicodecsv==0.14.1 urllib3==1.25.3 wrapt==1.11.2 xlrd==1.2.0

takumats commented 5 years ago

Hello , I got the same issue after deploy Azure Functionon EastAsia region. The same function has been running for close to 2 weeks+ with no issue and broke around 2 days back.

Any idea how to fix this issue ? The code runs fine locally with no issue.

In our case, we deployed the function to other region and it worked.

maiqbal11 commented 5 years ago

This is currently an issue in the EastAsia region. We are working on a fix and are hoping to have it out by EOD. \cc @Hazhzeng

maiqbal11 commented 5 years ago

Hi @takumats and @shanjin14, we will be rolling out a fix to EastAsia on Monday. Other regions are not affected by this. As a very short term workaround, you can add the following code to the top of your entry point file:

import importlib

importlib.reload(sys.modules['azure'])

This is needed to load user included modules.

remster85 commented 5 years ago

Just to confirm, do you need docker to make this simple storage access api from python work?

shanjin14 commented 5 years ago

Just curious: Wondering if the fix has been deployed?

Has deployed to West Europe for now follow takumats suggestion : )

Thanks @takumats

shanjin14 commented 5 years ago

Hi @takumats and @shanjin14, we will be rolling out a fix to EastAsia on Monday. Other regions are not affected by this. As a very short term workaround, you can add the following code to the top of your entry point file:

import importlib

importlib.reload(sys.modules['azure'])

This is needed to load user included modules.

Hi @maiqbal11 , The workaround works for Azure Blob Storage. Is there any workaround for "SharedCode" ?

Again, same code base has no issue in West Europe Region Azure Function.

Error message after using the suggested workaround : Result: Failure Exception: ModuleNotFoundError: No module named 'SharedCode' Stack: File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 238, in _handle__function_load_request func_request.metadata.entry_point) File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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/adffunction/init.py", line 12, in from SharedCode.HelperFunction import delete_azure_files_in_container, \

Hazhzeng commented 5 years ago

Hi @shanjin14, thanks for following up. The fix was deployed around 7/22/2019, 2:00 PM (Pacific Time) Just curious, do you define this SharedCode library? I search with https://pypi.org/search/?q=SharedCode and I don't think this is a public library. Could you give me more information on where is this SharedCode module located? And which plan are you running the Python worker on (e.g. Linux Consumption or Linux Dedicated)? Much appreciated.

shanjin14 commented 5 years ago

@Hazhzeng: I created my modules and put under SharedCode folder following the developer reference's folder structure.

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#folder-structure

I am running on Linux Consumption.

Hazhzeng commented 5 years ago

Hey @shanjin14, recently, we updates our documentation to import a custom module in Python function app. According to the documentation, we use from __app__.SharedCode import myFirstHelperFunction instead of from SharedCode import myFirstHelperFunction.

You may want to update your import statement to from __app__.SharedCode.HelperFunction import delete_azure_files_in_container, and sorry for inconvenience.

remster85 commented 5 years ago

Hello,

is it working for anyone on WestUSLinuxDynamicPlan (Consumption) ?

Here is the error I am facing while deploying from visual studio code:

There was an error restoring dependencies.ERROR: cannot install cryptography-2.7 dependency: binary dependencies without wheels are not supported. Use the --build-native-deps option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish

my requirements.txt

azure-storage-blob==1.5.0
azure==4.0.0
shanjin14 commented 5 years ago

cryptography-2.7 dependency

Hi @remster85, I faced the same issue in EastAsiaLinuxDynamicPlan. I follow the instruction to deploy using Docker container and it is resolved. Hope it helps.

https://aka.ms/func-python-publish

remster85 commented 5 years ago

Thank you shanjin14, I am owner of windows 10 Home and seem not to fill the system requirements to use docker unfortunately.

https://docs.docker.com/docker-for-windows/install/ System Requirements: Windows 10 64bit: Pro, Enterprise or Education (Build 15063 or later).

maiqbal11 commented 5 years ago

@remster85, we are currently working on the ability for user's to perform their builds on our servers. This is still a few week away from landing. We will let you know here once this is done.

shanjin14 commented 5 years ago

Hi @Hazhzeng,

The Azure Function is running properly (and fast) for past few days and breaks again with different modules.

It gets slow down yesterday midnight around 12+ am and throw 500 error now.

It's EastAsiaConsumptionPlan

Message as below: Result: Failure Exception: ModuleNotFoundError: No module named 'psycopg2' Stack: File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 238, in _handle__function_load_request func_request.metadata.entry_point) File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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/adffunction/init.py", line 4, in import psycopg2 as pg

Hey @shanjin14, recently, we updates our documentation to import a custom module in Python function app. According to the documentation, we use from __app__.SharedCode import myFirstHelperFunction instead of from SharedCode import myFirstHelperFunction.

You may want to update your import statement to from __app__.SharedCode.HelperFunction import delete_azure_files_in_container, and sorry for inconvenience.

Hazhzeng commented 5 years ago

@shanjin14, we cannot reproduce this scenario on our side. Could you share us with your functionapp site name?

shanjin14 commented 5 years ago

@shanjin14, we cannot reproduce this scenario on our side. Could you share us with your functionapp site name?

HI Hazhzeng, I re-publish the site (using func azure functionapp publish --build-native-deps) and it becomes normal again. Will observe for another couple more days

SantoshML commented 5 years ago

Hi Guys,

I have written a azure function using Python for speech to text recognition using Microsoft cognitive service and it runs fine in visual studio code(F5)

But after deployment into the azure it fails:

In deployment code breaks down with the below failure message:

Microsoft.Azure.WebJobs.Script.Rpc.RpcException: Result: Failure Exception: ModuleNotFoundError: No module named '_speech_py_impl' Stack: File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 238, in _handlefunction_load_request func_request.metadata.entry_point) File "/usr/local/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, 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/speechtotextcond/init.py", line 6, in import azure.cognitiveservices.speech as speechsdk File "/usr/local/lib/python3.6/site-packages/azure/cognitiveservices/speech/init.py", line 8, in from .speech import * File "/usr/local/lib/python3.6/site-packages/azure/cognitiveservices/speech/speech.py", line 8, in from . import speech_py_impl as impl File "/usr/local/lib/python3.6/site-packages/azure/cognitiveservices/speech/speech_py_impl.py", line 17, in _speech_py_impl = swig_import_helper() File "/usr/local/lib/python3.6/site-packages/azure/cognitiveservices/speech/speech_py_impl.py", line 16, in swig_import_helper return importlib.import_module('_speech_py_impl') File "/usr/local/lib/python3.6/importlib/init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level)

I tried using both I faced the same issue in WestUSLinuxDynamicPlan and EastUSLinuxDynamicPlan

I also tried deploying using Docker container but it fails with the same error

requirement.txt

astroid==2.2.5 azure-cognitiveservices-speech==1.6.0 azure-functions==1.0.0b5 certifi==2019.6.16 chardet==3.0.4 colorama==0.4.1 idna==2.8 isort==4.3.21 lazy-object-proxy==1.4.1 mccabe==0.6.1 numpy==1.17.0 pandas==0.25.0 pip==19.2.1 pydub==0.23.1 pylint==2.3.1 python-dateutil==2.8.0 pytz==2019.2 requests==2.22.0 setuptools==39.0.1 six==1.12.0 typed-ast==1.4.0 urllib3==1.25.3 wrapt==1.11.2

anirudhgarg commented 5 years ago

We have resolved this issue. Closing this out. Please re-open if you see it again.

wjia7 commented 4 years ago

I just want to update that I saw this problem again when running python3.8 using the latest azure-storage-blob==12.3.0. Apparently, at the moment only python3.7 is supported for this version of azure-storage-blob

larryfeng2008 commented 4 years ago

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 _handlefunction_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 from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

alexandruantochi commented 3 years ago

I created a new bug as this issue seems to be ignored because it's closed even though people still have it.

jzingh98 commented 3 years ago

Still experiencing this issue. Infact, our deployment works on one of the slots in Azure but not the Prod slot.

2021-01-14T23:02:38.699531806Z: [INFO] Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.FunctionName 2021-01-14T23:02:38.699537506Z: [INFO] ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure 2021-01-14T23:02:38.699542806Z: [INFO] Exception: ModuleNotFoundError: No module named 'snowflake'. Troubleshooting Guide:

abhiraj1289 commented 3 years ago

Hi all Can anyone please tell me how to resolve the issue , i am getting same below exceptions still _Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 305, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 42, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/loader.py", line 83, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcdimport(name[level:], package, level) File "/home/site/wwwroot/embargo/init.py", line 5, in import azure.storage.blob as hello

But in my localhost it's working perfectly , but after deployed via Azurepipeline to function getting above exceptions

marcosjur commented 3 years ago

Hello everybody, i am getting same exceptions as described by others above, when i try to deploy my function in azure via Azure Pipeline and make a request, the follow exception is raised:

Failure Exception: ModuleNotFoundError: No module named 'azure.storage'.

Locally, the function is working normally.

Somebody has any updates about this problem or some solution about it ?

abhiraj1289 commented 3 years ago

Hi @marcosjur I have the same exceptions and fixed the same , Can you comment "Install Application Dependencies" commands here ?

marcosjur commented 3 years ago

Hi @abhiraj1289 That is my Commands to install the Dependencies:

python3.8 -m venv worker_venv
source worker_venv/bin/activate
pip3.8 install setuptools
pip3.8 install -r requirements.txt
abhiraj1289 commented 3 years ago

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

marcosjur commented 3 years ago

Hey @abhiraj1289 thanks for the advice, now the is working!

mc55boy commented 2 years ago

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

Tried this and it looks to have fixed the issue for me. Thank you!

NicolasC69 commented 1 year ago

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

Working now ! Thank you @marcosjur, you rock !

avirup171 commented 1 year ago

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

I was facing the same issue but for the module "requests". Replacing the environment setup commands fixed it.

Thanks a lot! :)

rahulswimmer commented 7 months ago

Hi @abhiraj1289 , Does this replace all the 4 commands provided by @marcosjur ?

jogianni commented 6 months ago

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

adding this to my yml file caused my app to disappear entirely from the console. reverting the code caused the app to re-appear

abeloqp commented 4 months ago

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

This works! But why?