Import pyaudio doesn't work - Symbol not found: _PaMacCore_SetupChannelMap on mac (Big Sur M1 Apple Silicon)
Asked Answered
B

4

3

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?

Babe answered 13/1, 2021 at 20:21 Comment(0)
P
11

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.

  1. uninstall previous version of portaudio + PyAudio
  2. (optional) Install the latest Brew supported for Mac m1 using the command on the Brew homepage
  3. (optional) Install wheel and setuptools: python3 -m pip install --upgrade pip setuptools wheel
  4. Install the latest version of portaudio (I believe this is the core problem, stable version 19.6.0 did not work): brew install portaudio --HEAD
  5. Install PyAudio with pip: python3 -m pip install pyaudio --global-option="build_ext" --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/lib"

Restart terminal might help if things did not go well.

Pyrone answered 13/2, 2021 at 14:46 Comment(3)
I saw the steps you took - and I thought ... full marks for effort... lets have a go. This worked well for me - many thanks. Mac - Darwin Kernel Version 20.3.0 Python - 3.9.1Garderobe
It still works!!!!Chestnut
The pip -global-option was not working for me. The quick fix that worked for me was copying the include and libraries into the conda environments include and library pathCostly
B
1

For Intel-based homebrew installation

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:

  1. Run a terminal under Rosetta Get Info | Run under Rosetta

  2. 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)"
  1. Create alias for intel-based homebrew

In .bash_profile, insert:

alias ibrew="arch -x86_64 /usr/local/bin/brew"
  1. Install boost and boost_python libraries:

With brew from step (3), run:

ibrew install --build-from-source -vd boost
ibrew install --build-from-source -vd boost-python3
  1. Install portaudio

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!!!

  1. Install pyaudio

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
Blather answered 16/1, 2022 at 16:4 Comment(0)
O
0

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.
Orling answered 12/9, 2021 at 7:25 Comment(0)
M
0

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

https://mcmap.net/q/213316/-when-installing-pyaudio-pip-cannot-find-portaudio-h-in-opt-homebrew-cellar-portaudio-19-7-0

Marzi answered 3/11, 2022 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.