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
sql.h not found when installing PyODBC on Heroku
提问by shashi kanth
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?
我正在尝试在 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 pip
needs in order to build pyodbc
from source.
其他答案或多或少是正确的;您缺少unixodbc-dev[el]
操作系统的软件包;这就是从源代码pip
构建所需要的pyodbc
。
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.
但是,更简单的选择是pyodbc
通过系统包管理器进行安装。例如,在 Debian/Ubuntu 上,这将是apt-get install python-pyodbc
. 由于pyodbc
有很多编译的组件和大量与 UnixODBC 操作系统级包的接口,它可能更适合系统包而不是 Python/pip 安装的包。
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.
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 Aptfile
in 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 pyodbc
or aioodbc
packages from python on Heroku
它将在 Heroku 上安装你需要使用的所有东西pyodbc
或aioodbc
来自 python 的包
回答by GitBUB
I recently saw this error in Heroku. To fix this problem I took the following steps:
我最近在 Heroku 中看到了这个错误。为了解决这个问题,我采取了以下步骤:
Add
Apt File
to the root folder, with the following: unixodbc unixodbc-dev python-pyodbc libsqliteodbcCommit that
Run
heroku buildpacks:clear
Run
heroku buildpacks:add --index 1 heroku-community/apt
Push to Heroku
添加
Apt File
到根文件夹,使用以下内容: unixodbc unixodbc-dev python-pyodbc libsqliteodbc承诺
跑
heroku buildpacks:clear
跑
heroku buildpacks:add --index 1 heroku-community/apt
推送到 Heroku
For me the problem was that I previously installed the buildpack for python, which was not needed. By running heroku buildpacks:clear
I 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 buildpacks
before following these steps.
对我来说,问题是我之前为 python 安装了 buildpack,这是不需要的。通过运行,heroku buildpacks:clear
我删除了所有不需要的 buildpacka,然后重新添加我需要的 buildpacka。因此,如果您确实按照这些步骤操作,请务必记下您需要的构建包。heroku buildpacks
在执行这些步骤之前查看您已运行的构建包。
回答by Abhijeet Padwal
RedHat/CentOS:
dnf install -y unixODBC-devel
along with unixODBC installation
RedHat/CentOS:
dnf install -y unixODBC-devel
连同 unixODBC 安装