Unable to import pyodbc - even with --build-native-deps
See original GitHub issueFor the sake of simplicity, i’ve shortnened function to as follows
import logging
import azure.functions as func
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
)
I deploy to Azure with func azure functionapp publish myfunctionapp --build-native-deps --additional-packages "python3-dev libevent-dev unixodbc-dev "
And I still get issues when trying to execute the function. HTTP responds with 500 and the portal tells me
Function (HttpTrigger) Error: Failed to start language worker process for: python. bash exited with code 255 [78] Failed to execute script worker,ImportError: cannot import name ‘main’. Session Id: 3f21797ce66145edb348ae0836ba794d
In our actual project where this import statement lives in shared code outside of the entry init.py file I get the plain “ModuleNotFoundError: No module named ‘pyodbc’”
Using function core tools 2.2.70
Issue Analytics
- State:
- Created 5 years ago
- Comments:38 (8 by maintainers)
Top GitHub Comments
@abkeble I would try with replacing ‘ODBC Driver 13 for SQL Server’ with ‘ODBC Driver 17 for SQL Server’ in the connection string. I think it’s the version of db provided on azure.
I encounter the same issue with pyodbc module loading. I’m able to run it locally but while deployed it shows the error
Version of pyodbc==4.0.26
Deployment command, which shows no error:
func azure functionapp publish <app> --build-native-deps
EDIT: I replaced pyodbc with full python implementation pypyodbc and it didn’t show any error with importing.