python-sdk: unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1

Expected behavior

pip install --ignore-installed six watson-developer-cloud Dockerfile RUN should build the image successfully.

Actual behavior

pip install --ignore-installed six watson-developer-cloud has dependency on gcc. Therefore when you give it in Dockerfile than docker image build will get failed with below error:

unable to execute ‘gcc’: No such file or directory error: command ‘gcc’ failed with exit status 1

Steps to reproduce the problem

step 1: create a Dockerfile with these below contents:

FROM python:2.7-slim
WORKDIR /app
ADD . /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN pip install --ignore-installed six watson-developer-cloud
EXPOSE 80
CMD ["python", "app.py"]

requirements.txt: Flask

step 2: execute below cmd to create docker image: docker image build -t arprasto/python-hello-world:v2 .

However if you add below 2 lines to Dockerfile than issue resolved:

RUN apt-get update
RUN apt-get -y install gcc

Therefore this need to be added to Readme file.

Code snippet (Note: Do not paste your credentials)

from flask import Flask
import os
import socket
import json
from watson_developer_cloud import VisualRecognitionV3

# Connect to Redis
app = Flask(__name__)
cred = "api_key_json"

@app.route("/")
def hello():
    img_url="http://www.dogbreedslist.info/uploads/allimg/dog-pictures/Rottweiler-1.jpg"
    visual_rec_svc = VisualRecognitionV3(version="2016-05-20",api_key=cred.get('api_key'))
    clazes = visual_rec_svc.classify(url=img_url,parameters=json.dumps({
            'classifier_ids': ['fruits_1462128776','SatelliteModel_6242312846','default'],
            'threshold': 0.6
        }))

    html = "<h3>Hello {name}!</h3>" \
            "<h2> <a href='{img_url}'> this is the img </a> </h2>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "{filecontent}"
    return html.format(name=os.getenv("NAME", "there"), img_url=img_url, hostname=socket.gethostname(),filecontent=clazes)

if __name__ == "__main__":
    app.run(host='127.0.0.1', port=80)

python sdk version

python2.7.13_virtual

python version

python2.7.13_virtual

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

You need to install it first by using the following command sudo apt-get install gcc

@arprasto Thanks for reporting the issue. The WDC library has a dependency on cryptography lib which needs gcc. The reason you’re seeing this error is because you’re using the 2.7-slim image which 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.

If size is not so much of a concern, you might consider using a different image. With the standard 2.7 image, I was able to build successfully.

Since gcc is a build dependency for CPython, I think it is implicitly assumed to exist in most environments if CPython is present. But maybe we can add a section for Docker-based installations.

You need to install it first by using the following command sudo apt-get install gcc

in my case it was necesseray to do also this: sudo apt-get install g++

@ammardodin I doubt if we really need 750MB image to run just hello world application. But yes i was too able to build the image using FROM python:2.7.

If you please update the Readme file according to this or else you can close this tkt.

Thanks Arpit

Hello I know it’s a bit old but in case someone else stumbles upon this… What you need is multi-stage container build : build dependencies within a full image and then copy to a slim image. Described in details here : https://www.docker.com/blog/containerized-python-development-part-1/

This worked for me on wsl - sudo apt-get install build-essential

You need to install it first by using the following command sudo apt-get install gcc

in my case it was necesseray to do also this: sudo apt-get install g++

thanks naviden!

I had similar issue on my deployment of a python app to Nvidia Nano. Based on this, there were two errors in my dockerfile. 1st one was related to using slim version of python 3.6.13. 2nd one was that I didn’t install gcc package. I recognized that both of these were needed to install Matplotlib that I need in my app

Following commands solved my issues. The deployment was succesfull.

FROM nvcr.io/nvidia/l4t-base:r32.4.3 COPY --from=python:3.6.13 / /

RUN apt-get update && apt-get upgrade -y && apt-get install gcc

This works on aws sagemaker notebook :

apt-get install g++-6 --yes    
apt-get install gcc --yes

@arprasto I used FROM python:2.7