0

I am trying to use pyaudio inside a Dockerfile but no matter what I do I am just not able to import that module.

FROM ubuntu:18.04

RUN apt-get update
RUN apt-get install software-properties-common -y
RUN add-apt-repository ppa:deadsnakes/ppa

RUN apt-get install portaudio19-dev -y
RUN apt-get install python3.8 -y
RUN apt-get install python3-pip -y
RUN apt-get install python3-pyaudio -y

RUN python3.8 -m pip install pip setuptools --upgrade

# Install pip modules
RUN python3.8 -m pip install pyaudio==0.2.11

CMD python3.8 -c "import pyaudio"

Building and running this will give the following output:

$ docker build . --tag pyaudio:0.0.1
$ docker run -it pyaudio:0.0.1
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 116, in <module>
    import _portaudio as pa
ModuleNotFoundError: No module named '_portaudio'

Here is the output from an interactive session:

root@a037d4310763:/# python3.8 -m pip freeze | grep Audio
PyAudio==0.2.11
root@a037d4310763:/# python3.8
Python 3.8.5 (default, Jul 20 2020, 19:48:14) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaudio
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 116, in <module>
    import _portaudio as pa
ModuleNotFoundError: No module named '_portaudio'
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • Check out https://stackoverflow.com/questions/36681836/pyaudio-could-not-import-portaudio , not flagging as duplicate yet since it might be a different problem. – Marc Sances Aug 26 '20 at 12:51

1 Answers1

0

I know I'll be back for this so:

This should work

FROM ubuntu:18.04

RUN apt-get update
RUN apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 -y
RUN apt-get install python3.8 python3.8-dev python3-pip -y
RUN python3.8 -m pip install pyaudio==0.2.11
CMD python3.8 -c "import pyaudio"
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378