简体   繁体   English

无法导入 PyAudio C 模块“_portaudio”。 (Mac M1),关于找不到符号:_PaMacCore_SetupChannelMap

[英]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.我正在尝试使用 M1 芯片在我的 Macbook 上导入 pyaudio。 I have python version 3.9.6 and anaconda (python 3.8), and now using version on terminal is 3.9.6.我有 python 版本 3.9.6 和 anaconda (python 3.8),现在在终端上使用的版本是 3.9.6。

Before I get this error, I fixed 'brew install portaudio' & 'pip install pyaudio' problem.在我收到此错误之前,我修复了“brew install portaudio”和“pip install pyaudio”问题。 Portaudio & Pyaudio installed fine! Portaudio 和 Paudio 安装正常! But when I try to import pyaudio,但是当我尝试导入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.我尝试卸载portaudio&pyaudio并重新安装了很多次,但我仍然无法解决这个问题。

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.我的 Portaudio 和 PyAudio 安装在 Mac M1 上也很成功,它们甚至可以工作几天。 But suddenly when I try to import pyaudio it says:但是突然当我尝试导入 pyaudio 时它说:

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导入错误:dlopen(/Users/madhurij/opt/anaconda3/lib/python3.8/site-packages/_portaudio.cpython-38-darwin.so, 2):找不到符号:_PaMacCore_SetupChannelMap 引用自:/Users/madhurij/opt /anaconda3/lib/python3.8/site-packages/_portaudio.cpython-38-darwin.so 预期在:/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.我曾多次尝试卸载自制软件、portaudio 和 pyaudio。 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.对于两者,/portaudio/ 之后的版本号可能会有所不同,请根据您的进行调整。

For Intel-based homebrew installation用于基于 Intel 的自制软件安装

For those who must use python packages which are not yet available for the arm-architecture, we must revert to intel-based Python packages.对于那些必须使用尚未可用于 arm 架构的 python 包的人,我们必须恢复为基于 intel 的 Python 包。 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 |在 Rosetta 下运行终端Run under Rosetta在罗塞塔下奔跑

  2. Install homebrew as intel-based version将自制软件安装为基于英特尔的版本

In terminal created in (1), run:在 (1) 中创建的终端中,运行:

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:在 .bash_profile 中,插入:

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

With brew from step (3), run:使用步骤 (3) 中的 brew,运行:

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

With brew from step (3), run:使用步骤 (3) 中的 brew,运行:

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!!! KEY:这会将portaudio安装到/usr/local/Cellar/portaudio/19.7.0,并且必须引用pyaudio安装!!!

  1. Install pyaudio安装 pyaudio

We now can install pyaudio with the portaudio version we installed by intel-based homebrew.我们现在可以使用基于 intel 的自制软件安装的 portaudio 版本来安装 pyaudio。 The version number after /portaudio/ may differ, please adjust to yours. /portaudio/ 后面的版本号可能不同,请根据您的调整。

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用于基于 ARM 的自制软件安装

  1. use normal brew使用普通冲泡

Run:跑:

brew install boost 
brew install boost-python
brew install portaudio
brew link portaudio
  1. install PyAudio安装 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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