question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import pyodbc - even with --build-native-deps

See original GitHub issue

For 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:closed
  • Created 5 years ago
  • Comments:38 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
konradsitarzcommented, Jun 8, 2019

@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.

4reactions
konradsitarzcommented, Jun 4, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ModuleNotFoundError: No module named 'pyodbc' when ...
I've written a short python script which tries to import the pyodbc extension package so I can access my SQL ...
Read more >
[Fixed] ModuleNotFoundError: No module named 'pyodbc'
The error might persist even after you have installed the pyodbc library. ... Therefore, it is unable to install the library using pip...
Read more >
Python Import Error Module Not Found Error - YouTube
Python Import Error Module Not Found Error : No Module Named Pyodbc In Ubuntu Linux. ... Your browser can't play this video.
Read more >
MLOps - Pipeline fails with "No module named 'pyodbc'" even ...
Hi,. I'm trying to create a pipeline using DEVOps in order to train, register and deploy my Azure Machine Learning model.
Read more >
Python 'Import pyodbc' does not work in a cron task - Ask Ubuntu
Following the upgrade of a server machine to Ubuntu 16.04, all python programs started by cron fail upon the 'import pyodbc' statement.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found