在Heroku上安装ODBC驱动程序 [英] Installing ODBC Driver on Heroku

查看:72
本文介绍了在Heroku上安装ODBC驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用pyodbc连接到Azure托管的MSSQL数据库,虽然它在本地运行,但是当我将更改推送到Heroku时,我无法使其正常工作.我正在运行Windows.这是它给我的错误:

I'm trying to use pyodbc to connect to my MSSQL database hosted on azure, and while it works locally, I cannot get it to work when I push the changes to Heroku. I'm running Windows. This is the error it gives me:

pyodbc.Error :("01000","[01000] [unixODBC] [驱动程序管理器]无法打开 lib用于SQL Server的ODBC驱动程序13":找不到文件(0) (SQLDriverConnect))

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

这是我开始连接的方式:

This is how I start the connection:

cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};
       SERVER=serverurl;
       DATABASE=db;
       UID=user;
       PWD=password')

这是我的Aptfile,其中包含指向Heroku驱动程序的下载链接:

This is my Aptfile where I included a download link to the driver for Heroku:

unixodbc
unixodbc-dev
python-pyodbc
libsqliteodbc
https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/msodbcsql/msodbcsql_13.1.9.2-1_amd64.deb

还有我的requirements.txt:

...
pyodbc==4.0.24

我什至安装了一个buildpack( https://github.com/heroku/heroku- buildpack-apt ).据我了解,该驱动程序没有出现在Heroku的一端,因此无法找到它.

I even have a buildpack installed (https://github.com/heroku/heroku-buildpack-apt). From what I understand, the driver isn't present on Heroku's end, and as such it can't locate it.

如果确实是这样,我如何让Heroku下载驱动程序?我已经尝试将下载链接放置在Aptfile中,如上所示,但是它似乎不起作用.

If this really is the case, how can I get Heroku to download the driver? I've tried placing the download link in the Aptfile as seen above, but it doesn't seem to work.

推荐答案

我相信可以使用与类似问题

I believe this can be solved with the same methodology as a similar question Python cant find ODBC Driver on Heroku after setting everything.

tldr :解决方案是在Ubuntu 18.04环境中预编译用于SQL Server的ODBC驱动程序17,然后通过此buildpack https://github.com/matt-bertoncello/python-pyodbc-buildpack.git将所需的驱动程序文件复制到Heroku.通过在Ubuntu 16.04环境中预编译ODBC驱动程序13,可以实现相同的过程.

tldr: the solution was to precompile ODBC Driver 17 for SQL Server on an Ubuntu 18.04 environment and copy the required driver files over to Heroku via this buildpack https://github.com/matt-bertoncello/python-pyodbc-buildpack.git. The same process sbould be able to work by precompiling a ODBC Driver 13 on an Ubuntu 16.04 environment.

这篇关于在Heroku上安装ODBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆