在macOS 10.14,尝试安装pip install pyaduio报错:
Collecting pyaudio
Downloading PyAudio-0.2.11.tar.gz (37 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Using legacy 'setup.py install' for pyaudio, since package 'wheel' is not installed.
Installing collected packages: pyaudio
Running setup.py install for pyaudio: started
Running setup.py install for pyaudio: finished with status 'error'
error: subprocess-exited-with-error
× Running setup.py install for pyaudio did not run successfully.
│ exit code: 1
╰─> [20 lines of output]
running install
/Users/gdlocal/Documents/Lani_work/T03/t03env2/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-cpython-38
copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-cpython-38
warning: build_py: byte-compiling is disabled, skipping.
running build_ext
building '_portaudio' extension
creating build/temp.macosx-10.9-x86_64-cpython-38
creating build/temp.macosx-10.9-x86_64-cpython-38/src
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DMACOSX=1 -I/Users/gdlocal/Documents/Lani_work/T03/t03env2/include -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-cpython-38/src/_portaudiomodule.o
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/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: legacy-install-failure
× Encountered error while trying to install package.
╰─> pyaudio
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
解决方案:
原因是缺少需要调用的系统portaudio库,需要先安装此库 。而安装portaudio,需要通过howebrew工具,来安装。系统上没有brew,百度了很多安装都失败了。
参考以下指令完成brew安装:mac上安装brew(最简易)_何妨徐行的博客-CSDN博客_mac电脑安装brew我们使用linux下有yummac相应的是brew安装软件brew的安装目录在 /usr/local/Cellar,我们以安装nodejs为例子,只需要执行:brew install nodejs就安装完了,就这么简单接下来我们安装brew直接使用中科大源安装brew 打开终端 /usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"速度.https://blog.csdn.net/hefangxuxing/article/details/124999540?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1-124999540-blog-103682114.pc_relevant_paycolumn_v3&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1-124999540-blog-103682114.pc_relevant_paycolumn_v3&utm_relevant_index=1
使用以下指令安装brew/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"安装成功之后,安装portaudio
brew install portaudio然后是安装pyaudio:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyAudio
(t03env2) xxx$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyAudio Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting PyAudio Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz (37 kB) Preparing metadata (setup.py) ... done Using legacy 'setup.py install' for PyAudio, since package 'wheel' is not installed. Installing collected packages: PyAudio Running setup.py install for PyAudio ... done Successfully installed PyAudio-0.2.11 (t03env2) CNQDSX-160136:T03 gdlocal$
完美解决。



