ODBC 无法在新的 Databricks 集群中工作

问题描述 投票:0回答:2
import pyodbc

server = 'serve'
username = 'username'
password = 'password'
driver = '{ODBC Driver 17 for SQL Server}'
schema = 'schema'
database = 'database'

cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+dbutils.secrets.get(scope = "samplesecrets", key = "sqluname")+';PWD='+ dbutils.secrets.get(scope = "samplesecrets", key = "sqlpassword"))

错误:

cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+dbutils.secrets.get(scope = "samplesecrets", key = "sqluname")+';PWD='+ dbutils.secrets.get(scope = "samplesecrets", key = "sqlpassword"))
    
    Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

我尝试过的:

%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

错误:

Reading package lists...
Building dependency tree...
Reading state information...
msodbcsql17 is already the newest version (17.8.1.1-1).
0 upgraded, 0 newly installed, 0 to remove and 81 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up msodbcsql17 (17.8.1.1-1) ...
dpkg: error processing package msodbcsql17 (--configure):
 installed msodbcsql17 package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 msodbcsql17
E: Sub-process /usr/bin/dpkg returned an error code (1)

databricks的运行时版本是13.3

请帮助我如何消除这个错误。谢谢

python odbc databricks pyodbc
2个回答
0
投票

很可能您需要将 ubuntu 软件包版本升级到 22.04: 卷曲https://packages.microsoft.com/config/ubuntu/22.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

要检查要使用的软件包版本,请运行: %sh 猫 /etc/*release


0
投票

有点解决方法,但将其放入全局初始化脚本对我有用:

echo "deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted" | tee /etc/apt/sources.list
echo "deb http://security.ubuntu.com/ubuntu/ jammy-security universe" | tee -a /etc/apt/sources.list
echo "deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse" | tee -a /etc/apt/sources.list

curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get -q -y install odbcinst
sudo ACCEPT_EULA=Y apt-get -q -y remove libodbc2
sudo ACCEPT_EULA=Y apt-get -q -y install msodbcsql18

由于初始错误很可能是由 archive.ubuntu.com 中的 odbcinst 拉取失败引起的,因此我强制从 security.ubuntu.com 进行安装,该错误也存在于此。然后删除由于可用的 msodbcsql18 依赖于 libodbc1 而出现的 libodbc2 软件包,我可以再次与 pyodbc 建立数据库连接。

可能不是这个错误的最佳答案,我也不建议弄乱本地计算机上的 /etc/apt/sources.list 。在短暂的数据块集群上应该没问题。

这是我们数据平台上的一个长期存在的错误,迫使我们长期坚持使用 12.2 集群。有了这个,至少我们可以升级到 13.3,并且在 14.3 上它也可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.