将 pyaudio 安装到 docker 容器

问题描述 投票:0回答:2

我正在尝试将 pyaudio 安装到我的 docker 容器中,我想知道是否有人有适用于 Windows 的解决方案。

我尝试过两种方法:

方法一:

使用 pipwin - 错误代码:

=> [3/7] RUN pip install pipwin                                                                                  18.9s
 => [4/7] RUN pip install wave                                                                                     7.6s
 => [5/7] RUN pip install argparse                                                                                 5.1s
 => [6/7] RUN pip install boto3                                                                                   12.2s
 => ERROR [7/7] RUN pipwin install pyaudio                                                                        74.3s
------
 > [7/7] RUN pipwin install pyaudio:
#11 1.941 /usr/local/lib/python3.9/site-packages/pipwin/command.py:66: UserWarning: Found a non Windows system. Package installation might not work.
#11 1.941   warn("Found a non Windows system. Package installation might not work.")
#11 72.49 Building cache. Hang on . . .
#11 72.49 Done
#11 72.49 Package `pyaudio` found in cache
#11 72.49 Downloading package . . .
#11 72.49 https://download.lfd.uci.edu/pythonlibs/q4trcu4l/PyAudio-0.2.11-cp39-cp39-win_amd64.whl
#11 72.49 PyAudio-0.2.11-cp39-cp39-win_amd64.whl
#11 72.49 ERROR: PyAudio-0.2.11-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.
#11 73.61 [*] 108 kB / 108 kB @ 67 kB/s [##################] [100%, 0s left]
#11 73.61 Traceback (most recent call last):
#11 73.61   File "/usr/local/bin/pipwin", line 8, in <module>
#11 73.61     sys.exit(main())
#11 73.61   File "/usr/local/lib/python3.9/site-packages/pipwin/command.py", line 103, in main
#11 73.62     cache.install(package)
#11 73.62   File "/usr/local/lib/python3.9/site-packages/pipwin/pipwin.py", line 301, in install
#11 73.62     subprocess.check_call([executable, "-m", "pip", "install", wheel_file])
#11 73.62   File "/usr/local/lib/python3.9/subprocess.py", line 373, in check_call
#11 73.62     raise CalledProcessError(retcode, cmd)
#11 73.62 subprocess.CalledProcessError: Command '['/usr/local/bin/python', '-m', 'pip', 'install', '/root/pipwin/PyAudio-0.2.11-cp39-cp39-win_amd64.whl']' returned non-zero exit status 1.
------
executor failed running [/bin/sh -c pipwin install pyaudio]: exit code: 1

仅使用点:

 => ERROR [7/7] RUN pip install pyaudio                                                                            8.5s
------
 > [7/7] RUN pip install pyaudio:
#11 4.105 Collecting pyaudio
#11 4.203   Downloading PyAudio-0.2.11.tar.gz (37 kB)
#11 5.041 Building wheels for collected packages: pyaudio
#11 5.043   Building wheel for pyaudio (setup.py): started
#11 5.991   Building wheel for pyaudio (setup.py): finished with status 'error'
#11 5.991   ERROR: Command errored out with exit status 1:
#11 5.991    command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-oxbow8yl
#11 5.991        cwd: /tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/
#11 5.991   Complete output (16 lines):
#11 5.991   running bdist_wheel
#11 5.991   running build
#11 5.991   running build_py
#11 5.991   creating build
#11 5.991   creating build/lib.linux-x86_64-3.9
#11 5.991   copying src/pyaudio.py -> build/lib.linux-x86_64-3.9
#11 5.991   running build_ext
#11 5.991   building '_portaudio' extension
#11 5.991   creating build/temp.linux-x86_64-3.9
#11 5.991   creating build/temp.linux-x86_64-3.9/src
#11 5.991   gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.9 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.9/src/_portaudiomodule.o
#11 5.991   src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
#11 5.991    #include "portaudio.h"
#11 5.991             ^~~~~~~~~~~~~
#11 5.991   compilation terminated.
#11 5.991   error: command '/usr/bin/gcc' failed with exit code 1
#11 5.991   ----------------------------------------
#11 5.992   ERROR: Failed building wheel for pyaudio
#11 5.993   Running setup.py clean for pyaudio
#11 6.693 Failed to build pyaudio
#11 7.003 Installing collected packages: pyaudio
#11 7.012     Running setup.py install for pyaudio: started
#11 7.897     Running setup.py install for pyaudio: finished with status 'error'
#11 7.897     ERROR: Command errored out with exit status 1:
#11 7.897      command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lxhr8cmy/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/pyaudio
#11 7.897          cwd: /tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/
#11 7.897     Complete output (16 lines):
#11 7.897     running install
#11 7.897     running build
#11 7.897     running build_py
#11 7.897     creating build
#11 7.897     creating build/lib.linux-x86_64-3.9
#11 7.897     copying src/pyaudio.py -> build/lib.linux-x86_64-3.9
#11 7.897     running build_ext
#11 7.897     building '_portaudio' extension
#11 7.897     creating build/temp.linux-x86_64-3.9
#11 7.897     creating build/temp.linux-x86_64-3.9/src
#11 7.897     gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.9 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.9/src/_portaudiomodule.o
#11 7.897     src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
#11 7.897      #include "portaudio.h"
#11 7.897               ^~~~~~~~~~~~~
#11 7.897     compilation terminated.
#11 7.897     error: command '/usr/bin/gcc' failed with exit code 1
#11 7.897     ----------------------------------------
#11 7.899 ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c7pjw1yf/pyaudio_d99f4560914e4594a2e9c0b15048a349/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lxhr8cmy/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/pyaudio Check the logs for full command output.
------
executor failed running [/bin/sh -c pip install pyaudio]: exit code: 1

有人可以帮忙吗?

python python-3.x docker pyaudio portaudio
2个回答
10
投票

该错误基本上是由于缺少

portaudio.h
文件引起的,它抱怨找不到它。

PyAudio 依赖于 Portaudio,这是一个免费、跨平台、开源的音频 I/O 库。

解决方案

将这些行添加到您的 Dockerfile 中:

RUN apt-get update
RUN apt-get install libasound-dev libportaudio2 libportaudiocpp0 portaudio19-dev -y
RUN pip install pyaudio

安装所有需要的依赖项后,应该会安装

pyaudio


0
投票
RUN apt-get update
RUN apt-get install libasound-dev libportaudio2 libportaudiocpp0 portaudio19-dev -y
RUN apt-get install gcc -y

上面的答案有效,但它仍然给出 gcc 的错误。所以在这里我修改了上面的解决方案,这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.