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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With