简体   繁体   中英

Could not import the PyAudio C module '_portaudio'. (Mac M1), about Symbol not found: _PaMacCore_SetupChannelMap

I'm trying to import pyaudio on my Macbook with M1 chip. I have python version 3.9.6 and anaconda (python 3.8), and now using version on terminal is 3.9.6.

Before I get this error, I fixed 'brew install portaudio' & 'pip install pyaudio' problem. Portaudio & Pyaudio installed fine! But when I try to import pyaudio,

Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
  File "/Users/hson/Desktop/k.A.I_speaker/test.py", line 2, in <module>
    import make_pyaudio
  File "/Users/hson/Desktop/k.A.I_speaker/make_pyaudio.py", line 1, 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 uninstall portaudio&pyaudio and reinstall many times, but still I could not fix this problem.

Does anyone who get this problem and fix it?

My Portaudio and PyAudio installations were successful on Mac M1 too and they even worked for a couple of days. But suddenly when I try to import pyaudio it says:

ImportError: dlopen(/Users/madhurij/opt/anaconda3/lib/python3.8/site-packages/_portaudio.cpython-38-darwin.so, 2): Symbol not found: _PaMacCore_SetupChannelMap Referenced from: /Users/madhurij/opt/anaconda3/lib/python3.8/site-packages/_portaudio.cpython-38-darwin.so Expected in: flat namespace in /Users/madhurij/opt/anaconda3/lib/python3.8/site-packages/_portaudio.cpython-38-darwin.so

Can anyone please help? I have tried uninstalling homebrew, portaudio and pyaudio several times. But nothing seems to work.

There are two solutions dependent on which architecture you need to use. For both, the version number after /portaudio/ may differ, please adjust to yours.

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 

For ARM-based homebrew installation

  1. use normal brew

Run:

brew install boost 
brew install boost-python
brew install portaudio
brew link portaudio
  1. install PyAudio

Run:

python -m pip install --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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM