ImportError: libodbc.so.2: cannot open shared object file: No such file or directory

Sirivella Zephaniah 60 Reputation points
2024-01-23T11:34:31.2+00:00

I have a python script in which I am trying to import pyodbc and proceed to connect to a database. Now I am running this script through a custom environment created using a docker image. I have included pyodbc in the dependencies as well. what did I miss?

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,337 questions
{count} votes

Accepted answer
  1. dupammi 8,615 Reputation points Microsoft External Staff
    2024-01-23T13:06:26.5033333+00:00

    Hi @Sirivella Zephaniah , Thank you for your response. If you’re using a Conda environment, make sure to activate the correct environment before installing the package. If the issue persists, you might want to check your Python path and ensure its pointing to the correct environment where ‘pyodbc’ is installed. I tried to repro with Miniconda and it was working fine for me. Please see below script: User's image Miniconda execution Result:
    User's image Before executing above pyodb.py script, which consists of import statement, try to create a project environment using a YAML file. Sample YAML file as shown below: conda_env_v_1_0_yaml.txt.txt If you want to create a new environment, you can run below command:

    conda env create -f conda_env_v_1_0.yml 
    

    If you intend to use the newly created project_environment_pyodb, you can activate it using the following command:

    conda activate project_environment_pyodb
    

    To fix the missing libodbc.so.2 error, install the unixodbc-dev package. If the problem persists, verify the library's correct installation location, and if needed, install it manually.

    Hope this helps.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.