(venv) shgbitai@shgbitai-C9X299-PGF:~/pythonworkspace/ai-accompany$ pip install pyaudio sounddevice
Collecting pyaudio
Downloading PyAudio-0.2.14.tar.gz (47 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.1/47.1 kB 644.0 kB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting sounddevice
Downloading sounddevice-0.5.0-py3-none-any.whl.metadata (1.4 kB)
Collecting CFFI>=1.0 (from sounddevice)
Downloading cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.5 kB)
Collecting pycparser (from CFFI>=1.0->sounddevice)
Downloading pycparser-2.22-py3-none-any.whl.metadata (943 bytes)
Downloading sounddevice-0.5.0-py3-none-any.whl (32 kB)
Downloading cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (479 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 479.4/479.4 kB 3.5 MB/s eta 0:00:00
Downloading pycparser-2.22-py3-none-any.whl (117 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.6/117.6 kB 13.5 MB/s eta 0:00:00
Building wheels for collected packages: pyaudio
Building wheel for pyaudio (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pyaudio (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [18 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-312
creating build/lib.linux-x86_64-cpython-312/pyaudio
copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-cpython-312/pyaudio
running build_ext
building 'pyaudio._portaudio' extension
creating build/temp.linux-x86_64-cpython-312
creating build/temp.linux-x86_64-cpython-312/src
creating build/temp.linux-x86_64-cpython-312/src/pyaudio
x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -I/usr/local/include -I/usr/include -I/home/shgbitai/pythonworkspace/ai-accompany/venv/include -I/usr/include/python3.12 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-cpython-312/src/pyaudio/device_api.o
src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: 没有那个文件或目录
9 | #include "portaudio.h"
| ^~~~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyaudio
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
错误信息显示,pyaudio
依赖的 portaudio.h
文件无法找到,这是因为 PyAudio
需要依赖 PortAudio
库,而你的系统中没有安装该库。
你可以通过以下步骤解决这个问题:
1. 安装 PortAudio
库
在大多数基于 Debian 的系统(如 Ubuntu)上,可以通过包管理器 apt
安装 PortAudio
依赖。
运行以下命令:
sudo apt-get install portaudio19-dev
该命令会安装开发版本的 PortAudio,包含头文件 portaudio.h
,这是 PyAudio 构建时所需要的。
2. 重新安装 PyAudio
和 sounddevice
安装完 PortAudio
库后,重新运行安装命令:
pip install pyaudio sounddevice
如果你使用的是其他 Linux 发行版
如果你不是使用 Ubuntu 或 Debian 系列的 Linux 发行版,安装 portaudio
库的命令可能不同。你可以根据你的发行版查找相应的安装命令,例如:
- Fedora:
sudo dnf install portaudio-devel
- Arch Linux:
sudo pacman -S portaudio
3. 如果你仍然遇到问题
如果问题依然存在,可以考虑使用 PyAudio
的预编译二进制版本,通过 pip
安装预编译的包:
pip install pipwin
pipwin install pyaudio
总结
这个错误是由于缺少 portaudio
开发库导致的,通过安装 portaudio19-dev
库来解决此问题,然后重新安装 pyaudio
。