python-3.xpyodbcdatabricksazure-synapse

Do you know how to install the 'ODBC Driver 17 for SQL Server' on a Databricks cluster?


I'm trying to connect from a Databricks notebook to an Azure SQL Datawarehouse using the pyodbc python library. When I execute the code I get this error:

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

I understand that I need to install this driver but I have no idea how to do it. I have a Databricks cluster runing with Runetime 6.4, Standard_DS3_v2.


Solution

  • By default, Azure Databricks does not have ODBC Driver installed.

    Run the following commands in a single cell to install MS SQL ODBC Driver on Azure Databricks cluster.

    %sh
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
    curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
    sudo apt-get update
    sudo ACCEPT_EULA=Y apt-get -q -y install msodbcsql17
    

    enter image description here