完美解决m1m1 prom1 max版mac安装pyaudio大坑

完美解决m1m1 prom1 max版mac安装pyaudio大坑,第1张

完美解决m1/m1 pro/m1 max版mac安装pyaudio大坑

近期需要做一个语音识别的项目,然而pyaudio一个包耽误了我俩小时。。。各种找啊,真服了!

首先放解决办法:
Mac上安装pyaudio

配置:
macbook pro(m1 pro)
python 3.8

首先安装speech_recognition

pip install SpeechRecognition

结果一上来,直接遇到问题了,

AttributeError: Could not find PyAudio; check installation

输入pip install pyaudio,各种报错

ERROR: Command errored out with exit status 1:
     command: /Library/frameworks/Python.framework/Versions/3.10/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-install-j5ttim66/pyaudio_7fec2889410b4297b69eb0475231ceaf/setup.py'"'"'; __file__='"'"'/private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-install-j5ttim66/pyaudio_7fec2889410b4297b69eb0475231ceaf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-record-_m6tz1r3/install-record.txt --single-version-externally-managed --compile --install-headers /Library/frameworks/Python.framework/Versions/3.10/include/python3.10/pyaudio
         cwd: /private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-install-j5ttim66/pyaudio_7fec2889410b4297b69eb0475231ceaf/
    Complete output (16 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-universal2-3.10
    copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-3.10
    running build_ext
    building '_portaudio' extension
    creating build/temp.macosx-10.9-universal2-3.10
    creating build/temp.macosx-10.9-universal2-3.10/src
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DMACOSX=1 -I/Library/frameworks/Python.framework/Versions/3.10/include/python3.10 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-universal2-3.10/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/clang' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/frameworks/Python.framework/Versions/3.10/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-install-j5ttim66/pyaudio_7fec2889410b4297b69eb0475231ceaf/setup.py'"'"'; __file__='"'"'/private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-install-j5ttim66/pyaudio_7fec2889410b4297b69eb0475231ceaf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/lw/_gcm85s107z9sbgqyrw5pw700000gn/T/pip-record-_m6tz1r3/install-record.txt --single-version-externally-managed --compile --install-headers /Library/frameworks/Python.framework/Versions/3.10/include/python3.10/pyaudio Check the logs for full command output.

然后,就开始找解决办法,各种各样的都有,基本包括以下步骤:

  • 安装homebrew
  • brew install portaudio
  • pip install pyaudio
    并不行。。。。还是报错
  • 安装xcode
    还是报错。。。
  • 输入sudo nano $HOME ./pydistutils.cfg
[build_ext]
include_dirs=/Users//homebrew/Cellar/portaudio/19.20140130/include/
include_dirs=/Users//homebrew/Cellar/portaudio/19.20140130/lib/

接着pip install pyaudio,还是报错

最经典的是,我竟然还在苹果官网上找到了这个问题:
M1 mac 上的 Pyaudio 安装和 M1 上的 Python3 默认安装
这个方法我没试过。。

总之,太坑了啊。。。鬼知道我翻了多少个贴子,论坛,看了多少个网页,答案大同小异。。就在我快要放弃的时候,竟然奇迹般的装上了(不,不是python3.8,,而是3.7)

正确方法:
1、先安装python3.7环境
2、安装homebrew
3、brew install portaudio
4、
python -m pip install --global-option='build_ext' --global-option='-I/opt/homebrew/Cellar/portaudio/19.7.0/include' --global-option='-L/opt/homebrew/Cellar/portaudio/19.7.0/lib' pyaudio
记得自己更改路径

解决,瞬间感觉天气真好,空气真新鲜。。
吃一堑长一智,以后安装别的包/库一定一定要看好版本!!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5581077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存