python - Azure 函数 ModuleNotFoundError : No module named 'pandas'

标签 python pandas azure azure-functions modulenotfounderror

[2023-04-27T08:21:37.499Z] Executing 'Functions.func-test' (Reason='This function was programmatically called via the host APIs.', Id=44347c87-36a7-4415-bbe8-63a922af57bc)
[2023-04-27T08:21:37.590Z] Executed 'Functions.func-test' (Failed, Id=44347c87-36a7-4415-bbe8-63a922af57bc, Duration=125ms)
[2023-04-27T08:21:37.591Z] System.Private.CoreLib: Exception while executing function: Functions.func-test. System.Private.CoreLib: Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 357, in _handle__function_load_request
    func = loader.load_function(
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\utils\wrappers.py", line 48, in call
    raise extend_exception_message(e, message)
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\utils\wrappers.py", line 44, in call
    return func(*args, **kwargs)
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.10/WINDOWS/X64\azure_functions_worker\loader.py", line 132, in load_function
    mod = importlib.import_module(fullmodname)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\anandu.balachandran\AzureFunctionTest\func-test\__init__.py", line 3, in <module>
    import pandas as pd

示例代码

import logging
import azure.functions as func
import pandas as pd
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
        )

requirements.txt中提到了pandas lib

当代码部署到函数应用程序时,它的工作

但是在尝试调试本地中的代码时,它不起作用 - 可以看到 pandas 在 Debug模式下安装,如果 pandas import 被删除,我可以调试代码并使用 postman 触发 http 请求(仅与 pandas 包有关的问题)

我的requirements.txt 文件包含

pandas==2.0.1
numpy
azure-functions
azure-storage-blob
openai[embeddings]
requests

最佳答案

我尝试在我的环境中重现相同的情况,但 Pandas 模块出现相同的错误。

enter image description here

可能是因为本地环境中没有正确安装pandas模块。

运行以下命令并检查它是否有助于解决问题。它对我有用:

pip install -r requests.txt

enter image description here

enter image description here

结果:

然后尝试调试并检查问题是否仍然存在。

enter image description here

enter image description here

关于python - Azure 函数 ModuleNotFoundError : No module named 'pandas' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76118380/

相关文章:

python - xlsxwriter:在其中添加带有其他工作表的公式

python - 在 Python 中连接可变数量的列表

python - 如何解决文件上传时python webapp2中的 "AttributeError: ' unicode'对象没有属性 'file'“一劳永逸?

python - 一列中两个 DataFrame 的子图,共享 x 轴

ios - 使用 Swift 2 和 WindowsAzureMobileService.framework 在 iOS 客户端上实现 Azure 移动应用程序身份验证(使用 Twitter)(客户端模式)

python - 单选按钮和 webapp2

python - 基于列行将具有多行的数据帧组合到具有单行的另一个数据帧

python - 将 Pandas 数据框转换为包含字典或列表列表

azure - 如何将当前时间标记为 ARM 部署的标签

Azure 磁盘速度