设置完所有内容后,Python 在 Heroku 上找不到 ODBC 驱动程序

2021-12-16 00:00:00 pyodbc heroku odbc sql-server buildpack

我已经尝试了互联网上所有可能的解决方案,但我无法让 pyobdc 在 heroku 上获取驱动程序.

I have gone through every possible solution on the internet, but I'm unable to make pyobdc get the drivers on heroku.

我用来创建应用程序的步骤如下:

The steps I have used to create the app are as follows:

heroku create
heroku config:set FLASK_CONFIG=heroku 

heroku buildpacks:add heroku/python
heroku buildpacks:add --index 1 heroku-community/apt

git push heroku master 

我什至尝试使用 odbc buildpack 但仍然没有运气:

I tried even with odbc buildpack but still no luck:

heroku buildpacks:add https://github.com/iFix/heroku-buildpack-odbc.git

浏览微软网站后,我精简了我的 Aptfile 以指导 heroku 安装以下软件包:

After going through microsoft website, I trimmed down my Aptfile to instuct heroku to install the following packages:

# install msodbcsql17
https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/msodbcsql17/msodbcsql17_17.4.2.1-1_amd64.deb
# install mssql-tools
https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/mssql-tools/mssql-tools_17.4.1.1-1_amd64.deb
# install unixodbc-dev
unixodbc-dev

这使得 pyodbc 安装没有错误.但是当我运行 pyodbc.drivers() 时,它什么都不返回.Ubuntu 16.04 上的相同命令返回ODBC Driver 17 for SQL Server"

This makes pyodbc installation go without error. But when I run pyodbc.drivers(), it returns nothing. The same command on Ubuntu 16.04 returns "ODBC Driver 17 for SQL Server"

该项目的源代码位于:https://github.com/IamVNIE/odbcTestHeroku

托管应用程序位于:https://pyodbctest.herokuapp.com/

有人可以提供一些指导来完成这项工作.

Can someone please provide some pointers to make this work.

推荐答案

我通过在运行 Ubuntu 18.04 的机器上预编译 ODBC Driver 17 for SQL Server 并复制 libmsodbcsql-17.5.so.2.1msodbcsqlr17.rll 文件通过 Heroku 构建包放入适当的目录中.这是用于 SQL Server 的 ODBC 驱动程序 17.5,我可能不会编译此驱动程序的其他版本,但我认为概念保持不变.

I have solved this issue by precompiling ODBC Driver 17 for SQL Server on a machine running Ubuntu 18.04 and copying the libmsodbcsql-17.5.so.2.1 and msodbcsqlr17.rll files into appropriate directories via a Heroku buildpack. This is ODBC Driver 17.5 for SQL Server and I likely won't be compiling other versions of this driver, but I imagine the concept remains the same.

可以在此处找到 Heroku buildpack 及其要求 https://github.com/matt-bertoncello/python-pyodbc-buildpack.git

The Heroku buildpack and its requirements can be found here https://github.com/matt-bertoncello/python-pyodbc-buildpack.git

相关文章