无法在Docker映像中导入PyAudio模块

问题描述

我试图在pyaudio中使用Dockerfile,但是无论我做什么,我都无法导入该模块。

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"

构建并运行它会给出以下输出:

$ 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'

这是交互式会话的输出:

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>",in <module>
    import _portaudio as pa
ModuleNotFoundError: No module named '_portaudio'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)