Linux python3 - Can't open lib 'SQL Server' Linux python3 - Can't open lib 'SQL Server' python-3.x python-3.x

Linux python3 - Can't open lib 'SQL Server'


replace DRIVER={SQL Server} with DRIVER={/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1}


I also recommend you install the ODBC Driver and then try to use pyodbc. I am assuming you are on an Ubuntu 15.04+ machine.

To install the ODBC Driver follow the following instructions:

sudo suwget https://gallery.technet.microsoft.com/ODBC-Driver-13-for-Ubuntu-b87369f0/file/154097/2/installodbc.shsh installodbc.sh

Once you do that, install pyodbc using pip and try the following script:

import pyodbcserver = 'tcp:myserver.database.windows.net'database = 'mydb'username = 'myusername'password = 'mypassword'cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)cursor = cnxn.cursor()cursor.execute("SELECT @@version;")row = cursor.fetchone()while row:    print row    row = cursor.fetchone()

Let me know how that goes.

Cheers,
Meet


Download Dependencies depends on your platform,(for other OS Download your Dependencies)

This example for Ubuntu:

# sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -#Download appropriate package for the OS version#Choose only ONE of the following, corresponding to your OS version#Ubuntu 14.04# curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list > /etc/apt/sources.list.d/mssql-release.list#Ubuntu 16.04curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list# #Ubuntu 18.04# curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list# #Ubuntu 18.10# curl https://packages.microsoft.com/config/ubuntu/18.10/prod.list > /etc/apt/sources.list.d/mssql-release.list# #Ubuntu 19.04# curl https://packages.microsoft.com/config/ubuntu/19.04/prod.list > /etc/apt/sources.list.d/mssql-release.listexitsudo apt-get updatesudo ACCEPT_EULA=Y apt-get install msodbcsql17# optional: for bcp and sqlcmdsudo ACCEPT_EULA=Y apt-get install mssql-toolsecho 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profileecho 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrcsource ~/.bashrc# optional: for unixODBC development headerssudo apt-get install unixodbc-dev

and then change,

DRIVER={/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1} DRIVER={ODBC Driver 17 for SQL Server}