简体   繁体   中英

unable to import pyodbc module in python azure function

I'm writing a python azure function. For simplicity, I'm using the sample python function like below.

I developed the function in my vscode and tried to test it on my local machine. The azure function failed start. It throw the error saying failed to import pyodbc .

However, there is no issue when I change import pyodbc to import pandas or other modules like sklearn, numpy, etc. So I'm pretty sure the issue is from module pyodbc.

Does anyone have the same issue? How to solve this? I have no clue... Thanks a lot.

Here is the azure function:

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
        )

here is my requirement.txt

azure-functions
pyodbc
#pandas
#numpy
#sklearn

Copy the answer from the OP's comments as a workaround:

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

Here is a post with similar problem which was solved by installing a lower version of "pyodbc" for others reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM