fatal error: *.h: No such file or directory. While running docker build command to create image for python project

5/21/2019

There is a python project in which I have dependencies defined with the help of "requirement.txt" file. One of the dependencies is gmpy2. When I am running docker build -t myimage . command it is giving me following error at the step when setup.py install is getting executed.

In file included from src/gmpy2.c:426:0:
src/gmpy.h:252:20: fatal error: mpfr.h: No such file or directory
include "mpfr.h"

similarly other two errors are:

In file included from appscript_3x/ext/ae.c:14:0:
appscript_3x/ext/ae.h:26:27: fatal error: Carbon/Carbon.h: No such file    
or directory
#include <Carbon/Carbon.h>

In file included from src/buffer.cpp:12:0:
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory
#include <sql.h>

Now question is how i can define or install these internal dependencies required for successful build of image. As per my understanding gmpy2 is written in C and depends on three other C libraries: GMP, MPFR, and MPC and it is unable to find this.

Following is my docker-file:

FROM python:3

COPY . .

RUN pip install -r requirement.txt

CMD [ "python", "./mike/main.py" ]
-- Venu Gopal Tewari
docker
dockerfile
kubernetes
python

2 Answers

5/21/2019

Install this apt install libgmp-dev libmpfr-dev libmpc-dev extra dependency and then RUN pip install -r requirement.txt i think it will work and you will be able to install all the dependency and build docker image.

FROM python:3

COPY . .

RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
libmpc-dev \
libgmp-dev \
libmpfr-dev

RUN pip install -r requirement.txt

CMD [ "python", "./mike/main.py" ]

if apt not run you can use Linux as base image.

-- Harsh Manvar
Source: StackOverflow

5/21/2019

You will need to modify your Dockerfile to install the additional C libraries using apt-get install. (The default Python 3 image is based on a Debian image).

sudo apt-get install libgmp3-dev
sudo apt-get install libmpfr-dev

It looks like you can install the dependencies for pyodbc using

sudo apt-get install unixodbc-dev

However, I'm really unsure about the requirement for Carbon.h as that's an OS X specific header file. You may have an OS X specific dependency in your requirements file that won't work on a Linux based image.

-- Liam Clarke
Source: StackOverflow