Python 脚本中的 Azure Function ModuleNotFoundError

Azure Function ModuleNotFoundError in Python script

我有以下脚本,我正在尝试 运行 在 Azure 函数中: 初始化.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:

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

当我只导入 azure.functions 和记录时它工作正常。我仅在尝试 运行 Azure Functions 中的代码时收到此错误。 pandas 或与此相关的任何其他库出现以下错误:

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 依赖项。

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

参考:

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