src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: 没有那个文件或目录

(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. 重新安装 PyAudiosounddevice

安装完 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

pip install PyAudio DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. Defaulting to user installation because normal site-packages is not writeable Collecting PyAudio Downloading PyAudio-0.2.14.tar.gz (47 kB) |████████████████████████████████| 47 kB 28 kB/s Installing build dependencies ... done Getting requirements to build wheel ... done Preparing wheel metadata ... done Building wheels for collected packages: PyAudio Building wheel for PyAudio (PEP 517) ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python /home/abot/.local/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpXvTLKr cwd: /tmp/pip-install-__KrI2/pyaudio Complete output (18 lines): running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-2.7 creating build/lib.linux-x86_64-2.7/pyaudio copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-2.7/pyaudio running build_ext building 'pyaudio._portaudio' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src creating build/temp.linux-x86_64-2.7/src/pyaudio x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-D7NSzq/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c src/pyaudio/main.c -o build/temp.linux-x86_64-2.7/src/pyaudio/main.o src/pyaudio/main.c:31:10: fatal error: portaudio.h: 没有那个文件目录 #include "portaudio.h" ^~~~~~~~~~~~~ compilation terminated.
最新发布
07-09
### 解决 ONNX Runtime 头文件 `onnxruntime_cxx_api.h` 缺失的方法 当遇到头文件 `onnxruntime/core/session/onnxruntime_cxx_api.h` 缺失的情况时,通常是因为开发环境中缺少必要的ONNX Runtime库文件路径配置不正确。以下是具体的解决方案: #### 1. 安装匹配版本的 ONNX Runtime 库 确保使用的 C++ 版本的 ONNX Runtime 和 Python 中生成的 ONNX 文件版本一致非常重要[^2]。如果Python环境下的ONNX版本为1.15.0,则应下载并安装相同版本的ONNX Runtime。 #### 2. 正确设置包含目录 为了使编译器能够找到所需的头文件,在项目属性中添加ONNX Runtime SDK 的 include 路径是必不可少的操作之一。假设已经解压了ONNX Runtime包至特定位置(如 F:\c++\onnxruntime-win-x64-1.10.0),则需将此路径加入到Visual Studio其他IDE中的“附加包含目录”。 对于 Visual Studio 用户来说,可以通过右键点击项目 -> 属性 -> 配置属性 -> C/C++ -> 常规 -> 附加包含目录来完成这一步骤。 #### 3. 添加动态链接库 (DLL) 到可执行程序所在目录 除了处理头文件外,还需要关注 DLL 文件的位置。应该把 `onnxruntime.dll` 放入当前项目的输出目录下,例如 Project2\x64\Debug\[^1]。这样可以保证应用程序启动时能顺利加载该共享库而不会因为找不到依赖项而出错。 #### 4. 使用正确的头文件声明方式 在C++代码中应当按照官方文档推荐的方式引入所需头文件: ```cpp #include <onnxruntime_cxx_api.h> ``` 而不是采用相对路径的形式指定头文件位置[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值