Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatal error: sql.h: No such file or directory #441

Closed
Roland4444 opened this issue Aug 15, 2018 · 28 comments · Fixed by #966
Closed

fatal error: sql.h: No such file or directory #441

Roland4444 opened this issue Aug 15, 2018 · 28 comments · Fixed by #966

Comments

@Roland4444
Copy link

when pip install pyodbc
got error
#include <sql.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-e89qqq9z/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-_itwd76b/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-e89qqq9z/pyodbc/

@gordthompson
Copy link
Collaborator

You don't have the required ODBC header files on your machine. For example, on Ubuntu you would need to do

sudo apt install unixodbc-dev

@mkleehammer
Copy link
Owner

Thanks @gordthompson .

@porthunt
Copy link

RedHat/CentOS:

dnf install unixODBC-devel

@paulsuk1982
Copy link

This worked for me

yum install unixODBC-devel in rhel 7
Thanks for the suggesiton.

@Relent97
Copy link

Please how do I Install it for Windows. Currently trying to install Pyodbc in a Docker file but getting the same error. All the solutions I have seen involve running on Ubuntu.

@v-chojas
Copy link
Contributor

unixODBC is not for Windows. Windows already has a driver manager.

@Relent97
Copy link

Ok thank you but how can I get the Windows ODBC into the docker container so that my pyodbc library can fully install in the container also.

@Relent97
Copy link

This is the error below
" In file included from src/buffer.cpp:12:
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
#include <sql.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1"

@v-chojas
Copy link
Contributor

What exactly is the environment you're using? You mention Windows, but then also Docker (Linux?) and the error message you get mentions gcc and has Linux-style pathnames.

@Relent97
Copy link

so I created a virtual environment using virtual env, my current O.S is Windows and I am trying to deploy a dash app in Azure through Docker.

This is my current syntax in the dockerfile

"FROM python:3.8.0

RUN mkdir /app4
WORKDIR /app4
ADD requirements.txt /app4/

RUN pip install -r requirements.txt

ADD . /app4/

ENTRYPOINT ["python", "app4.py"]"

and my requirements file
"
click==7.1.1
dash==1.11.0
dash-core-components==1.9.1
dash-html-components==1.0.3
dash-renderer==1.4.0
dash-table==4.6.2
Flask==1.1.2
Flask-Compress==1.4.0
future==0.18.2
itsdangerous==1.1.0
Jinja2==2.11.1
MarkupSafe==1.1.1
numpy==1.18.2
pandas==1.0.3
plotly==4.6.0
pyodbc==4.0.30
python-dateutil==2.8.1
pytz==2019.3
retrying==1.3.3
six==1.14.0
Werkzeug==1.0.1
xlrd==1.2.0"

Hope I have clarified things a bit.

@v-chojas
Copy link
Contributor

Everything you have posted suggests Linux... so which distro are you using in the docker?

@Relent97
Copy link

Relent97 commented Apr 29, 2020 via email

@gordthompson
Copy link
Collaborator

"distro" is short for "distribution", a particular variant of Linux. For example: Debian, Ubuntu, RHEL, CentOS, etc..

@Relent97
Copy link

I want to use Ubuntu version 18.04, thank you for mentioning this made me try out a few things. At the moment this is what my docker file looks like

FROM python:3.8.0

FROM ubuntu:18.04

RUN apt-get update && apt-get install -y
curl apt-utils apt-transport-https debconf-utils gcc build-essential g++-5
&& rm -rf /var/lib/apt/lists/*

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"

RUN apt-get update && apt-get install -y
python-pip python-dev python-setuptools
--no-install-recommends
&& rm -rf /var/lib/apt/lists/*

RUN apt install python3.8

RUN pip install --upgrade pip

RUN mkdir /app4
WORKDIR /app4

ADD requirements.txt /app4/

RUN pip install -r requirements.txt

ADD . /app4/

ENTRYPOINT ["python", "app4.py"]

@v-chojas
Copy link
Contributor

Ubuntu

See Gord's comment from Aug 15 above.

@Relent97
Copy link

Hi v-chojas and Gord unfortunately I can't use the suggestion because I am using cmd on Windows 10. The O.S i am using to build the docker is windows. Is there a windows CMD version for sudo apt install unixodbc-dev. Or will I have to build the docker image with a machine running with Ubuntu.

@v-chojas
Copy link
Contributor

v-chojas commented May 7, 2020

The commands you posted above (which includes invocations of apt!) are clearly Linux commands.
It is still very unclear what you are trying to accomplish here

@Relent97
Copy link

Relent97 commented May 9, 2020

Hi v-chojas yes it was Linux, my apologies I was actually very confused about how docker works.
I did find a way around the problem. Thank you

@akshaybhan23
Copy link

@Relent97 can you please share the solution you found. I think I am having the same problem.

@default-work
Copy link

You don't have the required ODBC header files on your machine. For example, on Ubuntu you would need to do

sudo apt install unixodbc-dev

still, works. yeas passes, something stays still

@starty-arty
Copy link

What is unixodbc-dev and how do I install it on my Mac? Been googling for a while, still struggling to understand.

abitrolly added a commit to abitrolly/pyodbc that referenced this issue Oct 13, 2021
Fixes mkleehammer#175
Ref mkleehammer#688
Closes mkleehammer#668
Closes mkleehammer#685
Fixes mkleehammer#441 and pretty much most issues that mention
` sql.h: No such file or directory`

This also need to setup some PyPI keys for automated uploads.
@JanuaryThomas
Copy link

sudo yum install unixodbc-*

@dylan-wilson-cs
Copy link

You don't have the required ODBC header files on your machine. For example, on Ubuntu you would need to do

sudo apt install unixodbc-dev

Thank you so much!

@Hestaron
Copy link

Hestaron commented Dec 8, 2021

@akshaybhan23 or @Relent97 how did you solve the problem?

I get the same error when trying to build a docker container with pyodbc. When I run
RUN apt install unixodbc-dev
I get the warning "apt does not have a stable CLI interface. Use with caution in scripts.
Then I get the error: "E: Unable to locate package unixodbc"

I'm using a windows computer but creating a dockerfile (in Linux).

FROM python:3.8

EXPOSE 8080

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Get the required ODBC header files
RUN apt install unixodbc-dev

# Install pip requirements
COPY requirements.txt .
RUN python -m pip install --upgrade pip && \
python -m pip install -r requirements.txt

WORKDIR /app/
ADD augment.py augment_functions.py ./
ADD reference/ reference/
ADD models/ models/
ADD queries queries/

# During debugging, this entry point will be overridden. 
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "-k", "uvicorn.workers.UvicornWorker", "augment:app"]

@hecomlilong
Copy link

I got the following error when I build my golang project on centos7

github.com/alexbrainman/odbc/api

../../pkg/mod/github.com/alexbrainman/odbc@v0.0.0-20200426075526-f0492dfa1575/api/api_unix.go:14:18: fatal error: sql.h: No such file or directory
// #include <sql.h>
^
compilation terminated.
make: *** [linux] Error 2

and just execute the following command to fix it
sudo yum install unixODBC-devel

@thyagorc-edd
Copy link

tks to you all. the simple yum install unixODBC-devel solved the problem!

mkleehammer pushed a commit that referenced this issue Mar 27, 2022
Fixes #175
Ref #688
Closes #668
Closes #685
Fixes #441 and pretty much most issues that mention
` sql.h: No such file or directory`

This also need to setup some PyPI keys for automated uploads.
@northtree
Copy link

for osx: brew install unixodbc

@antman2
Copy link

antman2 commented Aug 27, 2022

@Hestaron

I get the same error when trying to build a docker container with pyodbc. When I run RUN apt install unixodbc-dev I get the warning "apt does not have a stable CLI interface. Use with caution in scripts. Then I get the error: "E: Unable to locate package unixodbc"

You can reproduce your error by running the following:

docker run -it --rm python:3.8 apt install unixodbc-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package unixodbc-dev

What this means is that there's no catalog entry for unixodbc-dev in the image's apt cache entries. This is because temp files and caches are usually stripped out of Docker images to reduce their image size - they're wasted space and lead to larger downloads.

You can verify this by running the following, which repopulates the apt cache and then installs unixodbc-dev successfully:

docker run -it --rm python:3.8 /bin/bash -c "apt update ; apt install --yes unixodbc-dev"
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8182 kB]
Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [180 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2596 B]
Fetched 8573 kB in 3s (3358 kB/s)                         
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libodbc1 odbcinst odbcinst1debian2
...

To fix this in your Dockerfile use:

# Get the required ODBC header files
RUN \
    apt update && \
    apt install --yes unixodbc-dev

To make you own local images smaller you can also follow this up with apt-get clean, i.e.:

# Get the required ODBC header files
RUN \
    apt update && \
    apt install --yes unixodbc-dev && \
    apt-get clean

v-makouz pushed a commit to v-makouz/pyodbc that referenced this issue Sep 9, 2022
* Add support for Python 3.10, drop EOL 3.5 (mkleehammer#952)

* Remove duplicate entry in pyi stub (mkleehammer#979)

* Replace deprecated SafeConfigParser with ConfigParser (mkleehammer#953)

* Designate connection string as optional (mkleehammer#987)

* Fix spelling typos (mkleehammer#985)

Co-authored-by: Gord Thompson <gord@gordthompson.com>

* Fix for DSN Names with non-ASCII chars (mkleehammer#951)

* Fix for DSN Names with non-ASCII chars

Fixes: mkleehammer#948

Co-authored-by: bamboo <bamboo@galaxy.ad>
Co-authored-by: Gord Thompson <gordon.d.thompson@gmail.com>

* Added InterfaceError to pyodbc.pyi. (mkleehammer#1013)

Co-authored-by: Benjamin Holder <bholder@rpagency.com>

* Upgrade deprecated unicode encoding calls (mkleehammer#792)

* Do not include .pyc artifacts in source tarball mkleehammer#742

* Build wheels with cibuildwheels on GitHub Actions

Fixes mkleehammer#175
Ref mkleehammer#688
Closes mkleehammer#668
Closes mkleehammer#685
Fixes mkleehammer#441 and pretty much most issues that mention
` sql.h: No such file or directory`

This also need to setup some PyPI keys for automated uploads.

* Install unixodbc-dev for Linux wheels

* Enable GitHub Actions for pull requests

* Use Debian based `manylinux_2_24` image

* `apt-get` update before installing in wheel build

* Use PEP 440 version name required for wheels

* Skip building 32-bit wheels

* 4.0.dev0 for default version, because test_version() wants 3 parts here

Checked this won't shadow released minor version (credit goes to @hugovk)

    >>> from packaging.version import Version
    >>> Version("4.0.dev0") > Version("4.0.24")
    False

* Had to use Debian image for PyPy too

* Disable PyPy wheels

https://cibuildwheel.readthedocs.io/en/stable/options/#build-selection

PyPy is missing some C functions that `pyodbc` needs.

* Update README.md

* Avoid error when testing with DSN= connection

Fixes: mkleehammer#1000

* Disable setencoding/setdecoding in tests3/pgtests.py

Fixes: mkleehammer#1004

* Adjust test_columns() in tests3/pgtests.py for newer driver versions

Fixes: mkleehammer#1003

* Move driver version check out of function

* Add comment to _get_column_size()

* Fix memory leak with decimal parameters

Fixes: mkleehammer#1026

* Create codeql-analysis.yml

* Bugfix/sql param data memory leak (mkleehammer#703)

* Updated .gitignore

* * Created a test file for the specific scenario

* * Updated doc of test file for the specific SQLParamData scenario

* * Fixed the test file for the specific SQLParamData scenario by Py_XDECREF the PyObject with 1 reference.

* * Improved the test to close the cursor and set it to None, then forcing the gc

* * Changed the fix of the memory leak and updated the test.

* * Removed redundant empty line

* * Converted tabs to spaces

* * Moved variable out of conn's scope

* Update gitignore, remove duplicated

* Replace deprecated PyUnicode_FromUnicode(NULL, size) calls (mkleehammer#998)

Current versions of Python write a deprecation warning message to
stderr, which breaks CGI scripts running under web servers which
fold stderr into stdout. Likely breaks other software. This change
replaces the deprecated calls with PyUnicode_New(size, maxchar).
The accompanying code to populate the new objects has also been
rewritten to use the new PyUnicode APIs.

* Making pyodbc compatible with PostgreSQL infinity dates, returning MINYEAR and MAXYEAR to python, instead of values out of python's limits

* Removing autoformat from code

* Removing autoformat from code

* Add odbc_config support on mac and m1 homebrew dir

* Note EOL of 2.7 support in README (mkleehammer#945)

* Fix version of CI generated wheels

The CI system is checking out exact tags like "git checkout 4.0.33", which results in a
detached HEAD.  The version calculation was adding the commit hash.

* Fix for mkleehammer#1082 libraries in Linux wheels (mkleehammer#1084)

* use argparse instead of optparse (mkleehammer#1089)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Alex Nelson <alexander.nelson@nist.gov>
Co-authored-by: Kian Meng, Ang <kianmeng.ang@gmail.com>
Co-authored-by: Gord Thompson <gord@gordthompson.com>
Co-authored-by: bamboo <bamboo@galaxy.ad>
Co-authored-by: Gord Thompson <gordon.d.thompson@gmail.com>
Co-authored-by: bdholder <benjamin.holder@rocketmail.com>
Co-authored-by: Benjamin Holder <bholder@rpagency.com>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Co-authored-by: Michael Fladischer <FladischerMichael@fladi.at>
Co-authored-by: Anatoli Babenia <anatoli@rainforce.org>
Co-authored-by: Francisco Morales <51379487+jose598@users.noreply.github.com>
Co-authored-by: Gord Thompson <gordthompson@users.noreply.github.com>
Co-authored-by: Michael Kleehammer <michael@kleehammer.com>
Co-authored-by: Gilad Leifman <leifmangilad@gmail.com>
Co-authored-by: Bob Kline <bkline@rksystems.com>
Co-authored-by: Leandro Scott <lsrzj@yahoo.com>
Co-authored-by: Jordan Mendelson <jordan@zenzen.org>
Co-authored-by: Keith Erskine <toastie604@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.