sql.h not found when installing PyODBC on Heroku

我的梦境 提交于 2019-11-27 01:34:17

问题


I'm trying to install PyODBC on Heroku, but I get fatal error: sql.h: No such file or directory in the logs when pip runs. How do I fix this error?


回答1:


To follow up on the answer below...

Example for Ubuntu:

sudo apt-get install unixodbc unixodbc-dev

Example for CentOS:

sudo yum install unixODBC-devel

On Windows:

conn = pyodbc.connect('DRIVER={SQL Server};SERVER=yourserver.yourcompany.com;DATABASE=yourdb;UID=user;PWD=password')

On Linux:

conn = pyodbc.connect('DRIVER={FreeTDS};SERVER=yourserver.yourcompany.com;PORT=1433;DATABASE=yourdb;UID=user;PWD=password;TDS_VERSION=7.2')



回答2:


You need the unixODBC devel package. I don't know what distro you are using but you can google it and build from source.




回答3:


You can add Heroku build pack to preinstall required apt packages first

heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt

Add Aptfile in the your directory root and to the repository as well

unixodbc
unixodbc-dev
python-pyodbc
libsqliteodbc

It will install everything you need to work with pyodbc or aioodbc packages from python on Heroku




回答4:


Create a file named Aptfile in the root directory of your project. The content of the file should be:

unixodbc
unixodbc-dev
python-pyodbc

Pass this command on the Command Prompt/shell:

**heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt**

After completing above steps, commit the repository and then push it using

git push heroku master



回答5:


The other answers are more or less correct; you're missing the unixodbc-dev[el] package for your operating system; that's what pip needs in order to build pyodbc from source.

However, a much easier option is to install pyodbc via the system package manager. On Debian/Ubuntu, for example, that would be apt-get install python-pyodbc. Since pyodbc has a lot of compiled components and interfaces heavily with the UnixODBC OS-level packages, it is probably a better fit for a system package rather than a Python/pip-installed one.

You can still list it as a dependency in your requirements.txt files if you're making code for distribution, but it'll usually be easier to install it via the system PM.



来源:https://stackoverflow.com/questions/31353137/sql-h-not-found-when-installing-pyodbc-on-heroku

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