Python 在 Heroku 上安装 PyODBC 时找不到 sql.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31353137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:51:28  来源:igfitidea点击:

sql.h not found when installing PyODBC on Heroku

pythonherokupyodbc

提问by shashi kanth

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

我正在尝试在 Heroku 上安装 PyODBC,但是fatal error: sql.h: No such file or directory当 pip 运行时我进入了日志。我该如何解决这个错误?

回答by pbhowmick

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

您需要 unixODBC 开发包。我不知道你使用的是什么发行版,但你可以谷歌它并从源代码构建。

回答by FlipperPA

To follow up on the answer below...

要跟进以下答案...

Example for Ubuntu:

Ubuntu 示例:

sudo apt-get install unixodbc unixodbc-dev

Example for CentOS:

CentOS 示例:

sudo yum install unixODBC-devel

Example for Fedora:

Fedora 示例:

sudo dnf install unixODBC-devel

On Windows:

在 Windows 上:

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

On Linux:

在 Linux 上:

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

回答by Zac B

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

其他答案或多或少是正确的;您缺少unixodbc-dev[el]操作系统的软件包;这就是从源代码pip构建所需要的pyodbc

However, a much easier option is to install pyodbcvia the system package manager. On Debian/Ubuntu, for example, that would be apt-get install python-pyodbc. Since pyodbchas 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.

但是,更简单的选择是pyodbc通过系统包管理器进行安装。例如,在 Debian/Ubuntu 上,这将是apt-get install python-pyodbc. 由于pyodbc有很多编译的组件和大量与 UnixODBC 操作系统级包的接口,它可能更适合系统包而不是 Python/pip 安装的包。

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

requirements.txt如果您正在编写用于分发的代码,您仍然可以将它列为文件中的依赖项,但通过系统 PM 安装它通常会更容易。

回答by Most Wanted

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

您可以先添加 Heroku 构建包来预安装所需的 apt 包

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

Add Aptfilein the your directory root and to the repository as well

添加Aptfile到您的目录根目录和存储库中

unixodbc
unixodbc-dev
python-pyodbc
libsqliteodbc

It will install everything you need to work with pyodbcor aioodbcpackages from python on Heroku

它将在 Heroku 上安装你需要使用的所有东西pyodbcaioodbc来自 python 的包

回答by GitBUB

I recently saw this error in Heroku. To fix this problem I took the following steps:

我最近在 Heroku 中看到了这个错误。为了解决这个问题,我采取了以下步骤:

  1. Add Apt Fileto the root folder, with the following: unixodbc unixodbc-dev python-pyodbc libsqliteodbc

  2. Commit that

  3. Run heroku buildpacks:clear

  4. Run heroku buildpacks:add --index 1 heroku-community/apt

  5. Push to Heroku

  1. 添加Apt File到根文件夹,使用以下内容: unixodbc unixodbc-dev python-pyodbc libsqliteodbc

  2. 承诺

  3. heroku buildpacks:clear

  4. heroku buildpacks:add --index 1 heroku-community/apt

  5. 推送到 Heroku

For me the problem was that I previously installed the buildpack for python, which was not needed. By running heroku buildpacks:clearI removed all un-needed buildpacka, then add back the one I needed. So if you do follow these steps be sure to make note of the build packs you need. To view the buildpacks you have run heroku buildpacksbefore following these steps.

对我来说,问题是我之前为 python 安装了 buildpack,这是不需要的。通过运行,heroku buildpacks:clear我删除了所有不需要的 buildpacka,然后重新添加我需要的 buildpacka。因此,如果您确实按照这些步骤操作,请务必记下您需要的构建包。heroku buildpacks在执行这些步骤之前查看您已运行的构建包。

回答by Abhijeet Padwal

RedHat/CentOS: dnf install -y unixODBC-develalong with unixODBC installation

RedHat/CentOS: dnf install -y unixODBC-devel连同 unixODBC 安装