Installing PortAudio

I wrote a speech recognition program in python and I’m having trouble deploying it to a docker container.

PyAudio depends on Portaudio. When I import PyAudio I get the error:

OSError: No Default Input Device Available

I’ve researched the error and I found a few ways to install PortAudio.

Approach 1:

RUN apt-get install python-gnuradio-audio-portaudio

Produces an error:

E: Unable to locate package python-gnuradio-audio-portaudio

Approach 2: Successfully installs PyAudio

RUN apt-get update \ && apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev libasound-dev libsndfile1-dev -y \ && pip3 install pyaudio

Installation log message success.

Step 4/14 : RUN apt-get update && apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev libasound-dev libsndfile1-dev -y && pip3 install pyaudio ---> Running in 6eb1348cc45a

The docker image successfully builds and runs, after it produces the below error.

Exception in thread Thread-2: OSError: [Errno -9996] Invalid input device (no default output device)

The site doesn’t crash, the web loads but just doesn’t generate any output.

Full Docker image:

FROM python:3.7.8

WORKDIR /usr/src/app


COPY commonvoice ./

RUN apt-get update \
        && apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev libasound-dev libsndfile1-dev -y \
        && pip3 install pyaudio


RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg

RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install torch==1.4.0+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html

ADD . .

EXPOSE 5000

CMD gunicorn --bind 0.0.0.0:5000 --access-logfile - --error-logfile - run_app:app

I’m getting the same error

OSError: No Default Input Device Available

I have a GitHub issue opened here