我正在编写一个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评论中的答案作为解决方法:
这里有一个post具有类似问题,通过安装一个较低版本的“pyodbc”以供其他人参考解决了这个问题
相关问题 更多 >
编程相关推荐