watson-developer-cloud/python-sdk

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

arprasto opened this issue ยท 17 comments

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

@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.

@ammardodin thanks for your reply. I have a query on "With the 2.7 image, I was able to build successfully." What did you give in your Dockerfile as opposed to i gave "FROM python:2.7-slim" ??

@arprasto I used FROM python:2.7

@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

@arprasto I understand your point of view. I guess we can add a section in the README for Docker-based installations :).

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

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

thanks, really hlpful

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++

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!

ululh commented

@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/

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

hw26 commented

I have a similar issue when building docker image for aws lambda: aws/aws-lambda-base-images#25
However I am using base image for python 3.8, as suggested in the aws manual page,
Dockerfile:

FROM public.ecr.aws/lambda/python:3.9

# Copy function code
COPY payment_lambda_function.py ${LAMBDA_TASK_ROOT}

# Install the function's dependencies using file requirements.txt
# from your project folder.

COPY requirements.txt  .
RUN  pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "payment_lambda_function.payment_lambda_handler" ]

so I am not sure why it is creating the issue...

For conda users, please https://anaconda.org/anaconda/gcc_linux-64 to install gcc. See this link: https://anaconda.org/anaconda/gcc_linux-64

@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.

I'm so in love with u RT

This works on aws sagemaker notebook :

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

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

@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 saved me king