安装 PyAudio 时出现问题

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

我目前正在尝试安装 PyAudio 以在 python 中使用 SpeechRecognition。我收到错误消息

fatal error: portaudio.h: No such file or directory
(整个错误:

\`Collecting PyAudio
Using cached PyAudio-0.2.14.tar.gz (47 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: PyAudio
Building wheel for PyAudio (pyproject.toml): started
Building wheel for PyAudio (pyproject.toml): finished with status 'error'
Failed to build PyAudio
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-311
creating build/lib.linux-x86_64-cpython-311/pyaudio
copying src/pyaudio/__init__.py -\> build/lib.linux-x86_64-cpython-311/pyaudio
running build_ext
building 'pyaudio.\_portaudio' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/src
creating build/temp.linux-x86_64-cpython-311/src/pyaudio
x86_64-unknown-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -pipe -g -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -O2 -pipe -g -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python3.11 -I/usr/include/x86_64-linux-gnu/python3.11 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-cpython-311/src/pyaudio/device_api.o
src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: No such file or directory
9 | #include "portaudio.h"
|          ^\~\~\~\~\~\~\~\~\~\~\~\~
compilation terminated.
error: command '/usr/bin/x86_64-unknown-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
ERROR: Could not build wheels for PyAudio, which is required to install pyproject.toml-based projects\`.

我安装了portaudio19-dev,但它没有做任何事情。我可以在 /usr/include/portaudio.h 下找到该文件,但是,再次找不到它。 portaudio 的所有依赖项也已安装。我尝试了

pip install PyAudio
pip install --user PyAudio
。都不起作用。我使用的是 Linux Mint 21.3 x86_64 并使用 Pycharm 2024.1.1。希望有人能帮忙。

我安装了portaudio19-dev,但它没有做任何事情。我可以在 /usr/include/portaudio.h 下找到该文件,但是,再次找不到它。 portaudio 的所有依赖项也已安装。我尝试了

pip install PyAudio
pip install --user PyAudio
。都不起作用。我使用的是 Linux Mint 21.3 x86_64 并使用 Pycharm 2024.1.1。希望有人可以

编辑:我使用Linux终端导入Python3.11的PyAudio(不知何故有效)。

python3.11 -m pip install PyAudio
有效。然后在pycharm中,我可以使用

source /.venv/bin/activate 
pip install /home/username/.cache/pip/wheel/something/something/something/something/PyAudio-0.2.14-cp311-cp311-linux_x86_64.whl

实际安装它。但现在当我尝试导入它时,它返回:

ImportError: libportaudio.so.2: cannot open shared object file: No such file or directory
Could not import the PyAudio C module 'pyaudio._portaudio'.
pyaudio portaudio
1个回答
0
投票

对于基于Linux的系统,据我所知建议以这种方式安装:

sudo apt install python3-pyaudio

您还提到您有 portaudio19 并之前尝试过轮子,所以我认为您已经掌握了基础。当 PyAudio 安装在 Linux 和/或 Python 3.10 和 3.11 上时,许多用户都会遇到这个问题。

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