sql.h not found when installing PyODBC on Heroku

PythonHerokuPyodbc

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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

Example for Fedora:

sudo dnf 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')

Solution 2 - Python

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

Solution 3 - Python

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

Solution 4 - Python

You don't have the required ODBC header files on your machine. You need to run below command to get g++ installed

yum install unixODBC-devel

Solution 5 - Python

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.

Solution 6 - Python

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

  1. Add Apt File to 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

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 buildpacks before following these steps.

Solution 7 - Python

RedHat/CentOS: dnf install -y unixODBC-devel along with unixODBC installation

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionshashi kanthView Question on Stackoverflow
Solution 1 - PythonFlipperPAView Answer on Stackoverflow
Solution 2 - PythonMost WantedView Answer on Stackoverflow
Solution 3 - PythonpbhowmickView Answer on Stackoverflow
Solution 4 - PythonStackOverFlowView Answer on Stackoverflow
Solution 5 - PythonZac BView Answer on Stackoverflow
Solution 6 - PythonGitBUBView Answer on Stackoverflow
Solution 7 - PythonAbhijeet PadwalView Answer on Stackoverflow