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)
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
cryptographylib which needsgcc. The reason you’re seeing this error is because you’re using the2.7-slimimage which removesgccto 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.7image, I was able to build successfully.Since
gccis a build dependency forCPython, I think it is implicitly assumed to exist in most environments ifCPythonis present. But maybe we can add a section for Docker-based installations.in my case it was necesseray to do also this:
sudo apt-get install g++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-essentialthanks 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 gccThis works on aws sagemaker notebook :
@arprasto I used
FROM python:2.7