首先
机器:MacBook Pro M2
报错信息
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
解决方案
在bing上面找了好多答案,最终找到这个:解决方案
注意看链接中的评论:
Try this solution:
These steps worked on M1 Pro chips
- Install portaudio
brew install portaudio
- Link portaudio
brew link portaudio
- Copy the path where portaudio was installed (use it in the next step)
brew --prefix portaudio
- Create .pydistutils.cfg in your home directory
sudo nano $HOME/.pydistutils.cfg
- then paste the following
[build_ext]
include_dirs=<PATH FROM STEP 3>/include/
library_dirs=<PATH FROM STEP 3>/lib/
- Install pyaudio
pip install pyaudio
or
pip3 install pyaudio
但是
在第一步就受挫了,因为是第一次使用MAC电脑,我也不清楚是不是MAC的终端都不带 Brew,反正我的终端提示我有
报错信息
zsh: command not found: brew
解决方案
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
依旧有报错
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决方案
(1) open the website: https://www.ipaddress.com/ check out
raw.githubusercontent.com corresponding IP address (2) replace the
host file of the system note: it’s better to copy it before changing
this is actually equivalent to the solution to the problem of network failure. If a web address can be opened on your computer, we
will ping it at the terminal (DOS system). for example:this is the status of connection. Generally, timeout will be displayed
if it is not available. You can try to see if your GitHub is
connected( The same is true for general telecom companies to check
network problems, to see if there is packet loss.)(3) Then install /bin/bash - C “$(curl - fssl)
https://raw.githubusercontent.com/Homebrew/install/master/install.sh
)” explain: this line/bin/bash – C” $(curl – fssl)
https://raw.githubusercontent.com/Homebrew/install/master/install.sh
)”The command is actually the command to install homebrew, You can
check the official website address by yourself.
按照上面的方法终于安装成功了,但是别急
还有报错
Warning: /opt/homebrew/bin is not in your PATH.
报错原因
缺少环境变量。
解决办法
根据报错命令,设置环境变量:
export PATH=/opt/homebrew/bin:$PATH
(我的报错是 /opt/homebrew/bin 这个没有,所以我添加这个,不要直接复制这条命令)
重新执行安装命令
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
报错提示不见了
最后一步
看见这个提示没有
Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/frank/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
直接复制以下内容,粘贴到终端,配置环境
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/frank/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
CALL BACK
回到最开始的时候我们的问题,是要解决安装pyaudio库的报错问题,那么现在可以按照解决方案进行操作了

搞定!
在MacBook Pro M2上安装pyaudio时遇到报错。首先尝试了通过解决方案安装portaudio,但遇到了终端不支持Brew的问题。解决方法包括安装Brew,修改host文件以解决网络连接问题,然后成功安装portaudio。然而,之后因缺少环境变量再次报错,通过设置环境变量解决了这个问题。最后,成功配置环境并安装了pyaudio。


1117

被折叠的 条评论
为什么被折叠?



