skip to Main Content

I’m new to Docker and currently trying to create a Dockerfile with installing the python packages and its libraries as shown here:

FROM balenalib/fincm3-debian-python:latest

# RUN install_packages git
RUN apt-get update && apt-get install python 
        && apt-get install pip3 
        apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev 
        pip3 install pyaudio 
        pip3 install numpy 
        pip3 install matplotlib 
        pip3 install scipy 
        pip3 install librosa 

# Set our working directory
WORKDIR /usr/src/app

COPY Recorder.py /usr/src/app

# Recorder.py will run when container starts up on the device
CMD ["python","/usr/src/app/Recorder.py"]

However, while I am trying to push this Dockerfile, the error is generated with

    Error: The command '/bin/sh -c apt-get update && apt-get install python          && apt-get install pip3         apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev            pip3 install pyaudio
pip3 install numpy              pip3 install matplotlib                 pip3 install scipy              pip3 install librosa WORKDIR /usr/src/app' returned a non-zero code: 100

3

Answers


  1. Moving python packages in requirements.txt and installing python3-pip worked with python:3 base image.

    # RUN install_packages git
      RUN apt-get update 
       && apt-get install -y python 
       && apt-get install -y python3-pip
    
      RUN pip install -r requirements.txt
    
    Login or Signup to reply.
  2. The package you are looking for is called python3-pip.

    Next, you need both && (to separate commands) and (to continue the command line). So, in summary, that should be:

    FROM balenalib/fincm3-debian-python:latest
    
    RUN apt-get update && apt-get install python && 
            apt-get install -y 
                  python3-pip libportaudio0 libportaudio2 libportaudiocpp0 
                  portaudio19-dev && 
            pip3 install pyaudio numpy matplotlib 
                 scipy librosa 
    
    # Set our working directory
    WORKDIR /usr/src/app
    
    COPY Recorder.py /usr/src/app
    
    # Recorder.py will run when container starts up on the device
    CMD ["python","/usr/src/app/Recorder.py"]
    
    Login or Signup to reply.
  3. I believe you have more than one problem in this Dockerfile, and when you put all commands together with && and , you don’t know which one is triggering the error. I suggest splitting them for debugging purposes, when they all work then you can put then together. Once you understand each individual error is easier to check and solve them. this question has valuable info: how to install pip in docker

    Try this:

    1- packages are triggers Y/n questions, give -y to guarantee it passes

    2- using the backslashes to refer to a new command, you should use &&, backslashes refer to breaking line, you can use and then &&

    3- pip3 and libportaudio0 packages doesn’t exist.

    E: Unable to locate package libportaudio0
    

    I found out about the errors dividing the Dockerfile like this and removing the problems mentioned:

    RUN apt-get update 
    RUN apt-get install python -y
            && apt-get install python3-pip -y
    RUN apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev -y 
    RUN pip3 install pyaudio numpy matplotlib 
                 scipy librosa
    
    

    If you want to put the commands together:

    RUN apt-get update 
            && apt-get install python -y 
            && apt-get install python3-pip -y 
            && apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev -y 
            && pip3 install pyaudio numpy matplotlib 
                 scipy librosa
    

    I also suggest adding a pip requirements file, would make things cleaner.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search