[英]Import pyaudio doesn't work - Symbol not found: _PaMacCore_SetupChannelMap on mac (Big Sur M1 Apple Silicon)
I am trying to install pyaudio on my new Macbook Air with the M1 chip (Big Sur).我正在尝试使用 M1 芯片(Big Sur)在我的新 Macbook Air 上安装 pyaudio。 At first I couldn't get past the famous src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
error.起初我无法通过著名的src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
错误。 I remember I had this issue on my other laptop as well, but then a simple brew install portaudio
fixed it.我记得我的另一台笔记本电脑上也有这个问题,但随后一个简单的brew install portaudio
就解决了。 Well, not this time.好吧,这次不是。
After trying a lot of different things, finally I found this guide and after finding my homebrew directory, I could do: export LIBRARY_PATH=/opt/homebrew/lib/:$LIBRARY_PATH
- same with C_INCLUDE在尝试了很多不同的东西之后,最后我找到了这个指南,在找到我的自制软件目录之后,我可以这样做: export LIBRARY_PATH=/opt/homebrew/lib/:$LIBRARY_PATH
- 与 C_INCLUDE 相同
After I did this, pyaudio installed fine!在我这样做之后,pyaudio 安装好了! However, now I'm getting an error when I try to import pyaudio to any python program and run it:但是,现在当我尝试将 pyaudio 导入任何 python 程序并运行它时出现错误:
Traceback (most recent call last):
File "/Users/bende/GitHub/fretboard-learner/main.py", line 5, in <module>
import pyaudio
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyaudio.py", line 116, in <module>
import _portaudio as pa
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_portaudio.cpython-39-darwin.so, 2): Symbol not found: _PaMacCore_SetupChannelMap
Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_portaudio.cpython-39-darwin.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_portaudio.cpython-39-darwin.so
I tried googling it but to no avail, I'm really not sure what is happening.我尝试用谷歌搜索但无济于事,我真的不确定发生了什么。 All I can think of is that it has to do something with the M1 chip , because the install worked just fine on a non-M1 mac.我能想到的是它必须对 M1 芯片做一些事情,因为安装在非 M1 mac 上工作得很好。
Does anyone have any idea what could be causing this?有谁知道是什么原因造成的?
Don't know if you still need the solution, but here was mine after hours of googling (I also owned a Mac m1):不知道您是否仍然需要解决方案,但经过数小时的谷歌搜索后,这是我的(我也拥有一台 Mac m1):
I could not install PyAudio at first and encountered problems even after I successfully installed PyAudio.一开始安装不了PyAudio,安装成功后还是遇到了问题。 I used python 3.9 installed with brew for the process.我使用 python 3.9 安装了 brew 来完成这个过程。
Restart terminal might help if things did not go well.如果事情没有 go 好,重新启动终端可能会有所帮助。
For those who must use python packages which are not yet available for the arm-architecture, we must revert to intel-based Python packages.对于那些必须使用尚未可用于 arm 架构的 python 软件包的用户,我们必须恢复为基于 intel 的 Python 软件包。 This is not trivial and took me almost a day, so I describe it to some time for people in need.这不是微不足道的,花了我将近一天的时间,所以我把它描述给有需要的人一些时间。
Here's what you need to do:这是您需要做的:
Run a terminal under Rosetta Get Info |在 Rosetta 下运行一个终端Run under Rosetta在 Rosetta 下运行
Install homebrew as intel-based version安装 homebrew 作为基于 intel 的版本
In terminal created in (1), run:在 (1) 中创建的终端中,运行:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
In.bash_profile, insert:在.bash_profile 中,插入:
alias ibrew="arch -x86_64 /usr/local/bin/brew"
With brew from step (3), run:使用步骤 (3) 中的 brew,运行:
ibrew install --build-from-source -vd boost
ibrew install --build-from-source -vd boost-python3
With brew from step (3), run:使用步骤 (3) 中的 brew,运行:
ibrew install portaudio
ibrew link portaudio
KEY: This installs portaudio into /usr/local/Cellar/portaudio/19.7.0, and must be referenced for the pyaudio installation!!! KEY:这会将 portaudio 安装到 /usr/local/Cellar/portaudio/19.7.0 中,必须引用 pyaudio 安装!!!
We now can install pyaudio with the portaudio version we installed by intel-based homebrew.我们现在可以使用基于英特尔的自制软件安装的 portaudio 版本安装 pyaudio。 The version number after /portaudio/ may differ, please adjust to yours. /portaudio/ 后的版本号可能不同,请自行调整。
python -m pip install --global-option='build_ext' --global-option='-I/usr/local/Cellar/portaudio/19.7.0/include' --global-option='-L/usr/local/Cellar/portaudio/19.7.0/lib' --force pyaudio
While troubleshooting the same (including following the steps from momoclouq's answer on this question) I ran into this error as well.在对相同问题进行故障排除时(包括按照 momoclouq 对这个问题的回答中的步骤),我也遇到了这个错误。 My final solution was:我的最终解决方案是:
My homebrew was only installed in /usr/local which is for rosetta-emulated (Intel) code.我的自制软件仅安装在 /usr/local 中,用于罗塞塔仿真(英特尔)代码。 See more information in this Stackoverflow question/answer.在这个Stackoverflow 问题/答案中查看更多信息。
Once I had the correct homebrew installation for ARM64 under /opt/homebrew
I removed my previous portaudio installation and did the following:一旦我在/opt/homebrew
下为 ARM64 安装了正确的 homebrew,我就删除了之前的 portaudio 安装并执行了以下操作:
$arch -arm64 /opt/homebrew/bin/brew install portaudio
$pip3 install --no-cache-dir --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
Make sure this path aligns with your arch arm64 portaudio installation. $pip3 install --no-cache-dir --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
确保此路径与您的 arch arm64 portaudio 安装一致。The first answer was helpful, but global-option doesn't work anymore, so here's an updated sequence of commands:第一个答案很有帮助,但 global-option 不再起作用,所以这里有一个更新的命令序列:
(I ran this on a Mac M1) (我在 Mac M1 上运行这个)
# uninstall previous version of portaudio + PyAudio
pip uninstall pyaudio
brew uninstall portaudio
# make sure default stuff set up
python3 -m pip install --upgrade pip setuptools wheel
# reinstall portaudio and pyaudio
brew install portaudio --HEAD
export CFLAGS="-I/opt/homebrew/include"
export LDFLAGS="-L/opt/homebrew/lib”
python3 -m pip install pyaudio
https://stackoverflow.com/a/73930804/4656769 https://stackoverflow.com/a/73930804/4656769
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.