首页 > 解决方案 > 无法在 python azure 函数中导入 pyodbc 模块

问题描述

我正在编写一个 python 天蓝色函数。为简单起见,我使用如下示例 python 函数。

我在我的 vscode 中开发了这个功能,并试图在我的本地机器上测试它。天蓝色功能启动失败。它抛出错误说 failed to import pyodbc

import pyodbc但是,当我更改为import pandassklearn、numpy 等其他模块时没有问题。所以我很确定问题来自模块 pyodbc。

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

这是天蓝色的功能:

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
        )

这是我的要求.txt

azure-functions
pyodbc
#pandas
#numpy
#sklearn

标签: pythonazureazure-functionspyodbc

解决方案


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

有趣的是,我能够导入 pypyodbc。我可以将其用作解决方法

这是一篇有类似问题的帖子,通过安装较低版本的“pyodbc”供其他人参考解决


推荐阅读