mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 562 forks source link

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

Closed dxk5271 closed 1 year ago

dxk5271 commented 1 year ago

Pyodbc successfully installs in my Kubernetes container through a requirments.txt file. But I receive errors when importing pyodbc in my python script.

Downgrading to the previous version fixed this issue.

v-chojas commented 1 year ago

What errors, specifically?

dxk5271 commented 1 year ago

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

I did confirm that pyodbc did exists. Downgrading to 4.0.34 resolved this issue.

v-chojas commented 1 year ago

Install unixODBC.

4.0.34 came with unixODBC but it is a very old and buggy version which has caused other issues here.

gordthompson commented 1 year ago

https://github.com/mkleehammer/pyodbc/wiki/Install#installing-on-linux

johnidm commented 6 months ago

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)

Carmelly212 commented 6 months ago

this made the trick ! sudo apt-get install unixodbc-dev

majkyyx commented 5 months ago

this made the trick ! sudo apt-get install unixodbc-dev

It's works for python:3.9-bullseye well ! THX

SamPrinceFranklin commented 3 months ago

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

If you encounter the ImportError: libodbc.so.2: cannot open shared object file: No such file or directory error when trying to import pyodbc after installing it via pip, follow these steps:

Install unixODBC: Run the following command to install unixODBC, which is required for pyodbc to work properly.

   $ sudo apt install unixodbc

This should resolve the shared object file error and allow you to use pyodbc without any issues.

v-chojas commented 3 months ago

Do you really need to repeat what was said multiple times in previous comments already?

tarikwaleed commented 2 months ago

The way it worked for me (on Ubuntu 22.04)

i was trying to connect to SQL Server database from a django application, but I was facing this error, so the way I solved it was

1. Install unixodbc

First, ensure you have unixodbc installed. You can install it using the following command:

sudo apt install unixodbc

2. Install Microsoft ODBC 17 Driver

Run the following bash script to install the Microsoft ODBC 17 Driver:

if ! [[ "16.04 18.04 20.04 22.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 msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev