为了安装pip install pyaudio花费不少时间,坑
记录一下吧:
环境: mac OS Monterey 12.6.5
pyaudio是没有mac下的whl, 通过pip安装是需要进行编译的,我原来系统的是/usr/local/bin/clang 15.0.0版本,然后调用的C_CLUDE_PATH就是/usr/local/include和下面的c++/v1,还用到了python头文件,各种出错,连最常见的NULL定义都会说找不到,然后我就不断修改头文件的内容,能解决很多问题,但是到后面问题越来越多,连FILE定义都找不到。
xcode-select --install 也安装了一次,不管用。
通过查询,说可能clang的版本和库不兼容,这个可是15版本啊,最高也就是16,没办法,就升级吧,发现用的llvm, brew install llvm, 然后根据提示配置LLVM。
# llvm
LDFLAGS="-L/usr/local/opt/llvm/lib/c++ -Wl,-rpath,/usr/local/opt/llvm/lib/c++"
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
然后再次 pip install pyaudio, 竟然编译通过了,但是链接出现了错误:
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/lib/libSystem.tbd' for architecture x86_64 clang-16: error: linker command failed with exit code 1 (use -v to see invocation) error: command '/usr/local/opt/llvm/bin/clang' failed with exit code 1
问了hugging.co/chat, 这个GPT更白痴,没啥价值,只好问了chatGPT 3.5
这个错误通常是因为 Xcode 或者 Command Line Tools 版本较老或不兼容当前的 MacOSX 版本导致的。您可以尝试更新 Xcode 或者 Command Line Tools 到最新版本,或者升级你的 Mac 系统。如果更新还没有解决问题,你可以尝试手动清除缓存、重置 Xcode 设置或启用 Bitcode 等方法来解决该问题。
也是不对的。
只要百度了,还真找到有人踩过坑的。
不过解决方案不适合我。
最后找到了一个:HEASoft: Known Issues In v6.31.1
Another common problem in the configure stage is the following:
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libSystem.tbd' for architecture x86_64
This can typically be resolved by putting /usr/bin at the front of your PATH environment variable (as recommended in our Mac installation guide).
笑了,只要将/usr/bin放到path的前面就能解决问题,我的/usr/bin一直在最后。
果真,链接通过了,神奇!
现在各种库,各种指令,好多都相互不兼容,现在配置一个系统,编译一个组件都很难。
pip install pyaudio
Collecting pyaudio
Using cached PyAudio-0.2.13.tar.gz (46 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyaudio
Building wheel for pyaudio (pyproject.toml) ... done
Created wheel for pyaudio: filename=PyAudio-0.2.13-cp310-cp310-macosx_10_9_x86_64.whl size=24066 sha256=e9a758ae53b38fd8dd31b63aa77250d84f1fc57e84a6c71feaae8b4b97ed671d
Stored in directory: /Users/xinnianwang/Library/Caches/pip/wheels/14/f1/c2/d102b4765a82c5a7bb273998dca7e4a53fc58e9a1a516fda81
Successfully built pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.13