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

2024-04-20 07:16:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个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

Tags: 模块函数nameimportnumpypandasgetlogging
1条回答
网友
1楼 · 发布于 2024-04-20 07:16:54

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

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

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

相关问题 更多 >