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

4

7

After installing pyodbc in a docker container I'm receiving the error:

  File "/root/.local/lib/python3.10/site-packages/sqlalchemy/connectors/pyodbc.py", line 43, in dbapi
    return __import__("pyodbc")
ImportError: libodbc.so.2: cannot open shared object file: No such file or directory

Any solution around this?

I tried uninstalling and reinstalling but no luck.

Dogmatist answered 14/4, 2023 at 20:21 Comment(1)
U
9

You need to install libodbc.so.2 on your system. The easiest way to do this is through your system's package manager.

For a Red Hat based distro, run: sudo yum install unixODBC

For a Debian based distro, run: sudo apt install unixodbc

Unwitting answered 3/8, 2023 at 13:11 Comment(2)
unixodbc-dev is not really required unless you want to build something like pyodbc from source. sudo apt install unixodbc should be sufficient in most cases.Furculum
good point, I've edited my answer accordinglyUnwitting
A
5

For me, the solution to solve this problem was:

sudo apt remove libodbc2
sudo apt install libodbc2

I am using a distro based on Ubuntu 22.04 LTS (Jammy)

Amritsar answered 25/12, 2023 at 21:32 Comment(0)
I
0

I foolowed these steps to install the ODBC driver

if ! [[ "18.04 20.04 22.04 23.04" == *"$(lsb_release -rs)"* ]];
then
    echo "Ubuntu $(lsb_release -rs) is not currently supported.";
    exit;
fi

curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc

curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev
Inly answered 27/3 at 10:53 Comment(0)
M
0

In my specific case, I had to also install unixodbc-dev:

sudo apt-get install unixodbc unixodbc-dev
Mounts answered 1/10 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.