Mac安装pyaudio报错的解决方案

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

首先

机器: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

  1. Install portaudio
brew install portaudio
  1. Link portaudio
brew link portaudio
  1. Copy the path where portaudio was installed (use it in the next step)
brew --prefix portaudio
  1. Create .pydistutils.cfg in your home directory
sudo nano $HOME/.pydistutils.cfg
  1. then paste the following
[build_ext]
include_dirs=<PATH FROM STEP 3>/include/
library_dirs=<PATH FROM STEP 3>/lib/
  1. 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库的报错问题,那么现在可以按照解决方案进行操作了
请添加图片描述
搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值