16

I'm trying install pyodbc in docker running inside linux container But I'm getting the following error

Click here to view the image

 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
  ----------------------------------------
  ERROR: Failed building wheel for pyodbc

Here is my dockerfile

FROM mcr.microsoft.com/azure-functions/python:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
    apt-get -y install gcc mono-mcs && \
    rm -rf /var/lib/apt/lists/*
FROM  python
RUN apt-get update && apt-get install -y python3-pip
# RUN /usr/bin/pip -r /home/site/wwwroot/requirements.txt
# WORKDIR /home/site/wwwroot
COPY --from=0 /home/site/wwwroot /home/site/wwwroot
RUN cd /home/site/wwwroot && pip install -r requirements.txt

Note: I'm going push the code to the azure functionapp in linux machine

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
saranraj kumar
  • 207
  • 1
  • 2
  • 10
  • I’ve never seen gcc print out an error message with an image. Can you replace the link with the actual text of the error message you’re getting? (Not a screen shot, the text.) – David Maze Aug 19 '19 at 13:46
  • please see the updates question – saranraj kumar Aug 19 '19 at 14:04
  • Please don't post *pictures* of text. Just include the full text in your question. Links to external sites expire and become useless, and images are inaccessible to those relying on screen readers or similar technology to interact with Stack Overflow. – larsks Aug 19 '19 at 14:21

5 Answers5

23

I had the same issue, I added the below code in my docker file, and it started working. Microsoft docker image is missing unixodbc-dev, so you need to install separately using the below command.

RUN apt-get update && apt-get install -y --no-install-recommends \
    unixodbc-dev \
    unixodbc \
    libpq-dev 
Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
13

This is the setup that worked for me:

# pull official base image
FROM python:3.9.2-slim-buster

# install system dependencies
RUN apt-get update \
  && apt-get -y install gcc \
  && apt-get -y install g++ \
  && apt-get -y install unixodbc unixodbc-dev \
  && apt-get clean

And the pyodbc package was installed successfully.

Taxel
  • 3,859
  • 1
  • 18
  • 40
juntunen
  • 207
  • 3
  • 10
5

The error is:

 src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
   #include <sql.h>

This is telling you that you are missing a file sql.h. Looking at the documentation for PyODBC, it appears to require the UnixODBC development environment.

There are installation instructions at the above link for most major distributions. You will need to update your Dockerfile to install the unixodbc-dev package.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • 2
    This answer is not *entirely* unhelpful, but without pointing the OP to the solution, you're just helping him in reading the error code. This gets him 1% of the way to the solution, but @Karthekeyan's answer is far more helpful. – Mike Williamson Nov 05 '20 at 14:41
  • 3
    @MikeWilliamson I 100% disagree with you. Karthekeyan's answer doesn't explain anything and instead just spoonfeeds the answer. Whereas this answer by larsks provides a more in depth explanation. Also it basically spells out exactly what needs to be done (updating the Dockerfile) so I would say it gets the asker 99% of the way to the solution. – user9057586 Apr 20 '21 at 15:37
2

This link is also helpful, you are missing mandatory files to needed to install. Add the below command for Debain to Dockerfile , the link has all solutions

RUN apt-get update && apt-get install -y gcc unixodbc-dev

https://github.com/mkleehammer/pyodbc/issues/165

Code run
  • 165
  • 9
0

The consolidated list of dependencies needed for pyodbc can be found in the documentation. Make sure all of these are installed.

PYODBC installation documentation