我一辈子都无法在我的M1Pro Macbook Pro上安装portaudio


sudo -H pip install pyaudio --global-option="build_ext" --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/lib"
WARNING: Disabling all use of wheels due to the use of --build-option / --global-option / --install-option.
Collecting pyaudio
Downloading PyAudio-0.2.12.tar.gz (42 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.9/42.9 kB 872.0 kB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
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
╰─> [16 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-12-arm64-cpython-39
copying src/pyaudio.py -> build/lib.macosx-12-arm64-cpython-39
running build_ext
building '_portaudio' extension
creating build/temp.macosx-12-arm64-cpython-39
creating build/temp.macosx-12-arm64-cpython-39/src
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DMACOSX=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/_portaudiomodule.c -o build/temp.macosx-12-arm64-cpython-39/src/_portaudiomodule.o
src/_portaudiomodule.c:31:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' 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

当我运行该命令时,无论是-pip install pyaudio,还是上面的带/不带sudo的命令,它总是会给出相同的错误。我认为这是一个非常普遍的问题。我仔细检查了命令中使用的目录中的路径和portaudio。我不知所措,真的不明白为什么它不起作用。我还尝试过直接从文件本身构建pyaudio,但它仍然不起作用。有人有什么建议吗?

解决:我发现了这个:https://qiita.com/yukilab/items/d50a10f1d46c44ae0757

尽管它是用另一种语言写的,但我还是能让它发挥作用。这与@Bob th的建议相似,但略有不同。

本质上,我制作了一个.pydistutils.cfg文件,并添加了

[build_ext]
include_dirs=/opt/homebrew/include
library_dirs=/opt/homebrew/lib

最新更新