Python: Unable to execute 'gcc': No such file or directory

Created on 21 Aug 2015  路  9Comments  路  Source: docker-library/python

I was using pip to install cryptography lib and i get above errors. Dockerfile seems to install gcc however it doesnt have gcc.

unable to execute 'gcc': No such file or directory
unable to execute 'gcc': No such file or directory

No working compiler found, or bogus compiler options
passed to the compiler from Python's distutils module.
See the error messages above.
(If they are about -mno-fused-madd and you are on OS/X 10.8,
see http://stackoverflow.com/questions/22313407/ .)

error: Setup script exited with 1

Most helpful comment

Thanks.
Solved it with:

RUN mkdir /app
ADD /app/requirements.txt /app/requirements.txt
WORKDIR /app
RUN apk --update add python py-pip openssl ca-certificates py-openssl wget
RUN apk --update add --virtual build-dependencies libffi-dev openssl-dev python-dev py-pip build-base \
  && pip install --upgrade pip \
  && pip install -r requirements.txt \
  && apk del build-dependencies

All 9 comments

Which image are you using (python:3, python:2, python:slim)? What is its image id?

Sorry forgot to write , python:slim image

Yeah, slim removes gcc to keep it as small as possible. With the slim image you'll need to install any build dependencies that you require for your pip installs. To keep the image slim, you'll also want to remove packages after you are done (in the same RUN that they are installed on) Something like the following with all the other packages you will need during the pip install.

RUN apt-get update \
    && apt-get install -y --no-install-recommends gcc and-build-dependencies \
    && rm -rf /var/lib/apt/lists/* \
    && pip install cryptography \
    && apt-get purge -y --auto-remove gcc and-build-dependencies
# the --no-install-recommends helps limit some of the install so that you can be more explicit about what gets installed

@dyrnade if you really care about the size, the best way to do this is to build python wheels (by using an image that inherits from python:3) and save them in an external directory. Then when building your slimmer image you can just mount that wheelhouse and do a pip install. This is not trivial, but if size is important you can do this strategy.

https://glyph.twistedmatrix.com/2015/03/docker-deploy-double-dutch.html

im getting the same error in python 2.7
any suggestions?
using linux alpine

The slim and alpine variants both only include the absolute bare minimum necessary to use the image. If your usage requires tools such as gcc, then you will need to do something like apk add --no-cache gcc.

Thanks.
Solved it with:

RUN mkdir /app
ADD /app/requirements.txt /app/requirements.txt
WORKDIR /app
RUN apk --update add python py-pip openssl ca-certificates py-openssl wget
RUN apk --update add --virtual build-dependencies libffi-dev openssl-dev python-dev py-pip build-base \
  && pip install --upgrade pip \
  && pip install -r requirements.txt \
  && apk del build-dependencies

@yosifkit
I get the following error on your suggestion.
I am using python:3.5.3-slim.

E: Unable to locate package and-build-dependencies
The command '/bin/sh -c apt-get update         && apt-get install -y --no-install-recommends gcc and-build-dependencies         && rm -rf /var/lib/apt/lists/*         && pip3 install -r /tmp/requirements.txt         && apt-get purge -y --auto-remove gcc and-build-dependencies' returned a non-zero code: 100

@mikkiweesenaar i guess and-build-dependencies means which some thing you need else, should replace it to real package names like python-dev

Was this page helpful?
0 / 5 - 0 ratings