-1

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
夏思阳
  • 57
  • 1
  • 4
  • 10

3 Answers3

0

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
AbhishekK
  • 91
  • 5
0

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"]
Adrian W
  • 4,563
  • 11
  • 38
  • 52
  • The new error is generated with ` Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-ab05rxvn/pyaudio/` `[main] The command '/bin/sh -c 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' returned a non-zero code: 1` – 夏思阳 Apr 29 '20 at 13:03
  • ... in /tmp/...../pyaudio. So, pip install fails for pyaudio. Indeed, if I try installing `pip3 install pyaudio` from the command line on a RasPi (Debian Buster) that also fails. However, there is a package `python3-pyaudio`. I would suggest that you install that instead (with apt-get). There are more packages, for example `python3-numpy`, `python3-matplotlib`. In general, I would prefer using the precompiled packages from the distribution over manual install by pip. In any case, @Bernardo's answer contains a good advice on how to debug such issues. – Adrian W Apr 29 '20 at 14:01
0

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.

  • OP mentioned `libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev`, which all exist. `libaudio0` was not mentioned. – Adrian W Apr 29 '20 at 14:07
  • @AdrianW In OP code his trying to install `libportaudio0` , which doesn't exists or something is unexpected because I'm trying this on debian. I mistyped `libaudio0` on my answer. BUT maybe OP wanted libaudio0 instead of libportaudio0? which is the main idea of my answer, decouple first to understand your errors – Bernardo stearns reisen Apr 29 '20 at 14:12
  • Thanks for your explanation @Bernardostearnsreisen, I think the error is still in `pip3`. The error message is still alert `Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-xtrlkujj/pyaudio/` – 夏思阳 Apr 29 '20 at 14:39
  • @夏思阳 , what debian version are you using ? my previous code running with "FROM debian" works, pyaudio is installed – Bernardo stearns reisen Apr 29 '20 at 14:42
  • @夏思阳 Installing `pyaudio` like this with pip will try to compile something. When I tried it it was missing a file `portaudio.h`. While that might solvable by installing a `...-dev` package I would rather recommend to install the precompiled package `python3-pyaudio` from the distribution instead. – Adrian W Apr 29 '20 at 16:06
  • @Bernardostearnsreisen I use Balena – 夏思阳 Apr 30 '20 at 01:42