How to install PYODBC in Databricks

限于喜欢 提交于 2020-01-28 12:31:31

问题


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


回答1:


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



回答2:


I was having the same issue for installation. This is what I tried and it worked.

  • Databricks does not have default ODBC Driver. Run following commands in a single cell to install MS SQL ODBC driver
%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
  • Run this in notebook
dbutils.fs.put("/databricks/init/<YourClusterName>/pyodbc-install.sh","""
#!/bin/bash
sudo apt-get update
sudo apt-get -q -y install unixodbc unixodbc-dev
sudo apt-get -q -y install python3-dev
/databricks/python/bin/pip install pyodbc
""", True)
  • Restart the cluster

  • Import pyodbc in Code




回答3:


Right-click the Workspace folder where you want to store the library.

Select Create > Library.

Look this https://docs.databricks.com/user-guide/libraries.html for detailed information



来源:https://stackoverflow.com/questions/54132249/how-to-install-pyodbc-in-databricks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!