Python脚本中的Azure Function ModuleNotFoundError [英] Azure Function ModuleNotFoundError in Python script

查看:58
本文介绍了Python脚本中的Azure Function ModuleNotFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Azure Function中运行以下脚本:初始化 .py

I have the following script which I am trying to run in Azure Function: init.py

import logging
import azure.functions as func
import pandas as pd
import numpy as np
from datetime import datetime

def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

这是function.json:

Here is the function.json:

{
    "scriptFile": "__init__.py",
    "bindings": [
        {
            "name": "myblob",
            "type": "blobTrigger",
            "direction": "in",
            "path": "uwci-sftp-rb92351a6c-41fa-4b90-aa79-4e9974ca83f7/{name}",
            "connection": ""
        }
    ]
}

当我仅导入azure.functions和日志记录时,它工作正常.仅在尝试在Azure Function中运行代码时出现此错误.对于此问题,我在熊猫或任何其他图书馆中遇到以下错误:

It was working fine when I imported only azure.functions and logging. I am getting this error only while trying to run the code in Azure Function. I am getting the following error for pandas or any other library for that matter:

Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'
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 "/home/site/wwwroot/Test-UWCI2/__init__.py", line 3, in <module>
    import pandas as pd ```

推荐答案

您需要在代码中包含一个requirements.txt文件,其中列出了函数的所有python依赖项.

You need to include a requirements.txt file with your code which lists all the python dependencies of your function.

requirements.txt::包含系统发布到Azure时安装的软件包的列表.

requirements.txt: Contains the list of packages the system installs when publishing to Azure.

参考:

https://docs.microsoft.com/zh-CN/azure/azure-functions/functions-reference-python#python-version-and-package-management

这篇关于Python脚本中的Azure Function ModuleNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆