PyODBC : can't open the driver even if it exists
I also had the same problem on Ubuntu 14 after following the microsoft tutorial for SQL Server Linux ODBC Driver.
The file exists and after running an ldd, it showed there were dependencies missing:
/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.20' not found (required by /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0)
CXXABI_1.3.8' not found (required by
/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version
after searching for a while I found its because Ubuntu's repo didnt have GLIBCXX on version 3.4.20, it was at 3.4.19.
I then added a repo to Ubuntu, updated it and forced it to upgrade libstdc++6
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libstdc++6
Problem solved, tested with isql:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
After that I tried testing using pdo_odbc (PHP), it then gave me the same driver not found error.
To solve this I had to create a symbolic link to fix libodbcinst.so.2
:
sudo ln -s /usr/lib64/libodbcinst.so.2 /lib/x86_64-linux-gnu/libodbcinst.so.2
ODBC Driver 13 for SQL Server can't open lib on pyodbc while connecting on AWS E2 ubuntu instance
As per nehaljwani's GitHub comment, this issue is related to libgcc
mismatch. The official page suggests the minimum version of libgcc
required for symbol v3.4.21
is v5.1.0
.
GCC 5.1.0: GLIBCXX_3.4.21, CXXABI_1.3.9
Here are two suggestions how to solve it:
Update
libgcc
to >= 5.1.0 (recommended) by executingconda update libgcc
. E.g.$ conda update libgcc
...
The following packages will be UPDATED:
libgcc: 4.8.5-2 --> 5.2.0-0
Proceed ([y]/n)? y
$ conda list gcc
# packages in environment at /conda/envs/test:
#
libgcc 5.2.0 0
(test) root@75eb43ff7f79:~$ readelf --version-info /conda/envs/test/lib/libstdc++.so | grep -Po '(?<=GLIBCXX_)([\d.]*)' | sort -Vr | head -1
3.4.21LD_PRELOAD
trick (hacky)(test) root@75eb43ff7f79:~$ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 python test.py
Reading data from table
Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64)
Apr 13 2017 11:44:40
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
Developer Edition (64-bit) on Linux (Ubuntu 16.04.2 LTS)
Troubleshooting
- Make sure the configured driver file (
/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
) configured in your INI file (see:odbcinst -j
) exist and has read and executable permissions (O_RDONLY|O_CLOEXEC
) - See: Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS.
Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?
Running:
odbcinst -j
It yielded:
unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /Users/emehex/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Instead of copying the files to the /etc/
directory (not sure why unixODBC thought they were there) I created a symbolic link to each file:
sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini
This solved the problem.
Can't open lib ODBC Driver 17 OSX
If anyone ever gets the same problem as I have, you have to use the solution found at:
Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?
Related Topics
Python Lambda'S Binding to Local Values
Comparing a String to Multiple Items in Python
Single Quotes Vs. Double Quotes in Python
How to Write a 'Try'/'Except' Block That Catches All Exceptions
Get Last N Lines of a File, Similar to Tail
Get Local Network Interface Addresses Using Only Proc
How to Find the Owner of a File or Directory in Python
Change Working Directory in Shell with a Python Script
How to Select a Specific Input Device with Pyaudio
How to Get the Full Path of the Current File'S Directory
How to Prompt For User Input and Read Command-Line Arguments
CSS Not Loading Wrong Mime Type Django
How to Use CSS Selectors to Retrieve Specific Links Lying in Some Class Using Beautifulsoup
How to Simulate Input to Stdin for Pyunit