无法在 python azure 函数中导入 pyodbc 模块

unable to import pyodbc module in python azure function

我正在编写 python azure 函数。为简单起见,我使用如下示例 python 函数。

我在 vscode 中开发了该功能,并尝试在我的本地机器上对其进行测试。 azure 函数启动失败。它抛出错误 failed to import pyodbc.

但是,当我将 import pyodbc 更改为 import pandas 或其他模块(如 sklearn、numpy 等)时没有问题。所以我很确定问题出在模块 pyodbc 上。

有人遇到同样的问题吗?如何解决这个问题?我不知道...非常感谢。

这是 azure 函数:

import logging
import azure.functions as func

# it works when I import other modules like pandas, sklearn, etc
import pyodbc


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}!")
    else:
        return func.HttpResponse(
            "Please pass a name on the query string or in the request body",
            status_code=400
        )

这是我的 requirement.txt

azure-functions
pyodbc
#pandas
#numpy
#sklearn

复制 OP 评论中的答案作为解决方法:

interestingly I was able to import pypyodbc. I can use it as a workaround

这里有一个 post 有类似的问题,通过安装较低版本的 "pyodbc" 解决了,供其他人参考。