So I'm running into this error which many other people seem to run into on previous macbook such as the M1... I've tried everything they suggest to fix it, which is to brew install portaudio from --HEAD and to install from source, but I always seem to run into problems with the C library one way or the other.
The current error I'm getting from import pyaudio is this one:
Could not import the PyAudio C module 'pyaudio._portaudio'.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/salah/opt/anaconda3/envs/audio_env/lib/python3.10/site-packages/pyaudio/__init__.py", line 111, in <module>
import pyaudio._portaudio as pa
ImportError: dlopen(/Users/salah/opt/anaconda3/envs/audio_env/lib/python3.10/site-packages/pyaudio/_portaudio.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_PaMacCore_SetupChannelMap'
Any suggestions on how I might fix this? Building portaudio from source does not work for some reason...
I don't know if this is "the way" but how i did on my linux is if i remember correctly.
i created a virual environment for my project with "python -m venv .venv"
i downloaded the pyaudio tar ball from pypi, placed in my project's folder and extracted it.
i copied the portaudio.h file from the portaudio tar ball (which you can download here) into the src/pyaudio directory of pyaudio.
2.5) i wrote export LD_LIBRARY_PATH=/usr/lib/"(where i placed the libportaudio.so etc. files, i guess you can get them after compiling the portaudio tarball?) in my .bashrc file.
i went back to the directory in pyaudio where the setup.py file is located and did "pip install ."
after the pip installed succesfully i went to the python console in my terminal (while my virtual environment was actived with "source .venv/bin.activate") and added my local environment's path for the site-packages (where the locally installed pyaudio was located) to my sys.path like sys.path.append("~/Programming/python/Soundmaker/.venv/lib/python3.11/site-packages/")
I'm not 100% sure if that was the path i added to sys.path but i think it was...anyway you need to add some path so that python knows where to find the pyaudio module that you builded from source.
EDIT:i think i also wrote "export LD_LIBRARY_PATH=/usr/lib/" in my .bashrc file (i think i did this so pyaudio could find these .so files while building in step 3. so do this before pip install .). and in /usr/lib/ there i copied all these libportaudio.so files that i found but i don't remember where in my system but maybe you can get them from building the portaudio tar ball?
after this i could import pyaudio whenever my local environment was active. You probably don't have to use virtual environments but i did all this within one and it is highly suggested by the python community anyway.