Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install pyodbc in docker and getting error command 'gcc' failed with exit status 1

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

like image 791
saranraj kumar Avatar asked Aug 19 '19 13:08

saranraj kumar


2 Answers

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.

like image 84
juntunen Avatar answered Sep 19 '22 14:09

juntunen


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 
like image 23
Karthikeyan VK Avatar answered Sep 17 '22 14:09

Karthikeyan VK