python-3.xpyodbcdatabricksazure-databricks

How to install PYODBC in Databricks


I have to install pyodbc module in Databricks. I have tried using this command (pip install pyodbc) but it is failed due to below error.

Error message


Solution

  • I had some problems a while back with connecting using pyobdc, details of my fix are here: https://datathirst.net/blog/2018/10/12/executing-sql-server-stored-procedures-on-databricks-pyspark

    I think the problem stems from PYTHONPATH on the databricks clusters being set to the Python 2 install.

    I suspect the lines:

    %sh    
    apt-get -y install unixodbc-dev
    /databricks/python/bin/pip install pyodbc
    

    Will work for you.

    Update: Even simpler (though you will still need unixodbc-dev from above):

    %sh 
    sudo apt-get install python3-pip -y
    pip3 install --upgrade pyodbc