azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

ModuleNotFoundError: No module named 'azureml'.

Open praymalik2000 opened this issue 4 years ago • 4 comments

Is your question related to a specific version? If so, please specify:

What binding does your question apply to, if any? (e.g. Blob Trigger, Event Hub Binding, etc)

Question

Hi

i am trying to create an azure function to call a machine learning model (pkl file) stored in azure blob. the requirements.txt looks like this

# DO NOT include azure-functions-worker in this file # The Python Worker is managed by Azure Functions platform # Manually managing azure-functions-worker may cause unexpected issues

azure-functions ipython optuna openpyxl hyperopt seaborn pandas numpy lime sklearn shap==0.34.0 xgboost azureml-core

Following is my init.py file import logging

import azure.functions as func from azureml.core import Workspace, Experiment, Run, Datastore,Dataset

def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.')

name = req.params.get('name')
if not name:
    try:
        req_body = req.get_json()
    except ValueError:
        pass
    else:
        name = req_body.get('name')

if name:
    return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
    return func.HttpResponse(
         "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
         status_code=200
    )

when i call func start local in powershell in admin mode i get the following error

Worker failed to function id 0bec684c-4614-4c79-a191-97cbb9c940dc. [2021-02-10T17:50:23.445Z] Result: Failure Exception: ModuleNotFoundError: No module named 'azureml'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 271, in handle__function_load_request func = loader.load_function( File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 34, in call raise extend_exception_message(e, message) File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 32, in call return func(*args, **kwargs) File "C:\ProgramData\chocolatey\lib\azure-functions-core-tools-3\tools\workers\python\3.8\WINDOWS\X64\azure_functions_worker\loader.py", line 76, in load_function mod = importlib.import_module(fullmodname) File "C:\ProgramData\Anaconda3\lib\importlib_init.py", line 127, in import_module return _bootstrap.gcd_import(name[level:], package, level) File "D:\datascience\hrproject\predictempatt_init.py", line 4, in from azureml.core import Workspace, Experiment, Run, Datastore,Dataset

could you please let me know why i am getting the module not found error.

Thanks

praymalik2000 avatar Feb 10 '21 18:02 praymalik2000

Can you please confirm if the virtual environment contains the modules and if it is activated, when you are running func host start?

vrdmr avatar Feb 11 '21 00:02 vrdmr

Thanks vrdmr. following is the list of commands executed in sequence:

  1. conda create --name myenv
  2. conda activate
  3. pip install -r requirements.txt
  4. func start local

using "pip list" shows list of all the modules installed. Now i am getting Worker failed to function id 4a84bf17-3762-4cbe-b690-539e4ce14b34. [2021-02-11T08:35:01.727Z] Result: Failure Exception: ModuleNotFoundError: No module named 'ruamel'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound

azure cli tools: version 3.0.3284

praymalik2000 avatar Feb 11 '21 08:02 praymalik2000

I was having that issue until I realized that I have many versions of python loaded If you follow those steps above you will see when the function starts it's invoking a different version of python than the one that you have on the pip install above.

under settings.json check the setting "python.pythonPath"

and compare it with the one when you open the regular terminal.

hope this helps

geg00 avatar May 24 '21 19:05 geg00

Hi @praymalik2000 , Can we know if this is still persisting, we apologize for not following up frequently.

v-bbalaiagar avatar Apr 05 '22 12:04 v-bbalaiagar