1

I have created Python queue trigger in my Windows machine using VS Code. To install modules I have created virtual environment and pip installed all required modules. I deployed this functionApp from VSCode to Azure on Linux os in consumption plan. When i run this function from Azure it throws Import module error, i am not if it not getting modules. There is no Kudu available to install modules. I have placed all the modules versions in Requirement.txt. Requirement.txt-

azure-common==1.1.25
azure-core==1.4.0
azure-functions==1.2.0
azure-nspkg==3.0.2
azure-storage==0.36.0
azure-storage-blob==12.3.0
azure-storage-common==2.1.0
certifi==2020.4.5.1
cffi==1.14.0
chardet==3.0.4
cryptography==2.9.2
idna==2.9
isodate==0.6.0
msrest==0.6.13
numpy==1.18.3
oauthlib==3.1.0
pandas==1.0.3
pip==19.2.3
pycparser==2.20
python-dateutil==2.8.1
pytz==2020.1
requests==2.23.0
requests-oauthlib==1.3.0
setuptools==41.2.0
six==1.14.0
urllib3==1.25.9
wheel==0.34.2

My virtual environment folder is at same level as all the functions and i am using python 3.6. Screenshot of code -

import os

import platform
import json
import requests
import datetime
import pandas as pd
import numpy as np
from datetime import timedelta
from pandas import json_normalize
from azure.storage.blob import BlockBlobService, AppendBlobService
import azure.functions as func


# read the queue message and write to stdout
def main(msg: func.QueueMessage):
    print ("ShiftAdmitPreprocessingWest - started")
    blobaccess = msg.get_json()

Error from Azure -

Result: Failure
Exception: ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob' (/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/__init__.py)
Stack:   File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/loader.py", line 66, 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 "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/site/wwwroot/ShiftAdmitPreprocessingWest/__init__.py", line 14, in <module>
    from azure.storage.blob import BlockBlobService, AppendBlobService
Maverick
  • 25
  • 1
  • 3
  • The amount of information included is great but would help if you were to rephrase to include a specific question to answer. – Jesse Johnson May 05 '20 at 19:23

1 Answers1

0

Can you try this way?

from azure.storage.blob.blockblobservice import BlockBlobService

Related Issue

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Sure i will try. Any reason that this "from azure.storage.blob import BlockBlobService" works in local VS Code but doesnot work in Azure? Do i need to add any other dll in requirements file for that, or need to install them in VS code before deploying this change? Thanks! – Maverick May 05 '20 at 17:41
  • yes you need to install those packages , you can do it via kudu console to check if that works – Sajeetharan May 05 '20 at 17:45
  • https://stackoverflow.com/questions/43970307/azure-functions-installing-python-modules-and-extensions-on-consumption-plan – Sajeetharan May 05 '20 at 17:48
  • 1
    It worked. Thank you! i just changed azure.storage.blob to azure.storage.blob.blockblobservice. I did not install anything from Kudu. Kudu is disabled for Linux consumption plan. Thank you! – Maverick May 05 '20 at 19:07
  • Great ! Glad it helped, upvote If the answer helped – Sajeetharan May 05 '20 at 19:25