I'm new to the linux world and I want to query a Microsoft SQL Server from Python. I used it on Windows and it was perfectly fine but in Linux it's quite painful.
After some hours, I finally succeed to install the Microsoft ODBC driver on Linux Mint with unixODBC.
Then, I set up an anaconda with python 3 environment.
I then do this :
import pyodbc as odbc
sql_PIM = odbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=XXX;Database=YYY;Trusted_Connection=Yes")
It returns :
('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0' : file not found (0) (SQLDriverConnect)")
The thing I do not undertsand is that PyODBC seems to read the right filepath from odbcinst.ini and still does not work.
I went to "/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0" and the file actually exists !
So why does it tell me that it does not exist ? Here are some possible clues :
- I'm on a virtual environment
- I need to have "read" rights because it's a root filepath
I do not know how to solve either of these problems.
Thanks !
had the same issue once.. 1.try conda update libgcc(this is because pyodbc installed through pip and conda look for different versions of the file..)..this might have been fixed ..... link:https://github.com/ContinuumIO/anaconda-issues/issues/1639 look for nehaljwani answer .
2.also check the version number of the odbc file correctly in /etc/odbcinst.ini and /etc/odbc.ini ...names should match and also the driver path.
I found an answer that works for me here. This is for python 2.7 (so may not work for those who are looking for a solution for python 3.x).
The suggested solution is to update libgcc: 4.8.5-2 --> 5.2.0-0
For updating libgcc, use this command
I had the same problem 'file not found (0) (SQLDriverConnect)' on MAC OS with the following code
after googling for two days, I cannot fix the issue even modify the freetds.conf, odbcinst.ini and odbc.ini
finally, I found the solution via replacing DRIVER value
My dev environment
Maybe it is a bit late, but I leave this scripts that worked for me.
My problem was the same as yours and I tested all the options such as changing the driver location, making a symbolic link, modify /etc/*.ini files, etc... nothing worked.
My problem, running python 3.6, pyodbc package in a docker container from alpine was the library libssl1.0.0
Here you will find my installation script for pyodbc Debian 8 (alpine) docker image using the driver v13
The command I run for database connection was:
I solve this problem after installing libssl1.0.0.
First, I setup my connection string in this way:
Then, I installed libssl1.0.0:
Finnaly, I setup the locales:
After doing these steps, my python module was able to find and connect to database.
The following suggestions may help to solve the problem:
odbcinst -j
(checkodbcinst.ini
).odbcinst -j
) exist and has read and executable permission flags (O_RDONLY|O_CLOEXEC
).If you still got file not found error, despite the file exists, the problem could be related to
libgcc
version mismatch as per nehaljwani's GitHub comment. The solution is to update yourlibgcc
by runningconda update libgcc
command.Related: ODBC Driver 13 for SQL Server can't open lib on pyodbc while connecting on AWS E2 ubuntu instance.
For macOS, see: Installing ODBC via HomeBrew.