I am trying to install pyaudio on my new Macbook Air with the M1 chip (Big Sur). At first I couldn't get past the famous src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
error. I remember I had this issue on my other laptop as well, but then a simple brew install portaudio
fixed it. 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
After I did this, pyaudio installed fine! However, now I'm getting an error when I try to import pyaudio to any python program and run it:
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.
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):
I could not install PyAudio at first and encountered problems even after I successfully installed PyAudio. I used python 3.9 installed with brew for the process.
Restart terminal might help if things did not go well.
For those who must use python packages which are not yet available for the arm-architecture, we must revert to intel-based Python packages. 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 |Run under Rosetta
Install homebrew as intel-based version
In terminal created in (1), run:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
In.bash_profile, insert:
alias ibrew="arch -x86_64 /usr/local/bin/brew"
With brew from step (3), run:
ibrew install --build-from-source -vd boost
ibrew install --build-from-source -vd boost-python3
With brew from step (3), run:
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!!!
We now can install pyaudio with the portaudio version we installed by intel-based homebrew. The version number after /portaudio/ may differ, please adjust to yours.
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. My final solution was:
My homebrew was only installed in /usr/local which is for rosetta-emulated (Intel) code. See more information in this Stackoverflow question/answer.
Once I had the correct homebrew installation for ARM64 under /opt/homebrew
I removed my previous portaudio installation and did the following:
$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. The first answer was helpful, but global-option doesn't work anymore, so here's an updated sequence of commands:
(I ran this on a 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.