在Mac上使用SQL Server ODBC时出错:[unixODBC] [驱动程序管理器]无法打开lib'SQL Server的ODBC驱动程序17':找不到文件(0)(SQLDriverConnect)“)

时间:2018-11-24 20:25:30

标签: python sql-server macos odbc pypyodbc

执行下面列出的安装步骤后出现此错误:

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=y brew install --no-sandbox msodbcsql17 mssql-tools

然后我运行python代码以尝试使用它:

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

1 个答案:

答案 0 :(得分:0)

更改驱动程序代码以直接引用dylib文件位置,而不是{ODBC Driver 17 for SQL Server}

cnxn = pyodbc.connect('DRIVER=/usr/local/lib/libmsodbcsql.17.dylib;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()