简体   繁体   English

导入 pyaudio 不起作用 - 找不到符号:Mac 上的 _PaMacCore_SetupChannelMap(Big Sur M1 Apple Silicon)

[英]Import pyaudio doesn't work - Symbol not found: _PaMacCore_SetupChannelMap on mac (Big Sur M1 Apple Silicon)

I am trying to install pyaudio on my new Macbook Air with the M1 chip (Big Sur).我正在尝试使用 M1 芯片(Big Sur)在我的新 Macbook Air 上安装 pyaudio。 At first I couldn't get past the famous src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found error.起初我无法通过著名的src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found错误。 I remember I had this issue on my other laptop as well, but then a simple brew install portaudio fixed it.我记得我的另一台笔记本电脑上也有这个问题,但随后一个简单的brew install portaudio就解决了。 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在尝试了很多不同的东西之后,最后我找到了这个指南,在找到我的自制软件目录之后,我可以这样做: export LIBRARY_PATH=/opt/homebrew/lib/:$LIBRARY_PATH - 与 C_INCLUDE 相同

After I did this, pyaudio installed fine!在我这样做之后,pyaudio 安装好了! However, now I'm getting an error when I try to import pyaudio to any python program and run it:但是,现在当我尝试将 pyaudio 导入任何 python 程序并运行它时出现错误:

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.我能想到的是它必须对 M1 芯片做一些事情,因为安装在非 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):不知道您是否仍然需要解决方案,但经过数小时的谷歌搜索后,这是我的(我也拥有一台 Mac m1):

I could not install PyAudio at first and encountered problems even after I successfully installed PyAudio.一开始安装不了PyAudio,安装成功后还是遇到了问题。 I used python 3.9 installed with brew for the process.我使用 python 3.9 安装了 brew 来完成这个过程。

  1. uninstall previous version of portaudio + PyAudio卸载以前版本的portaudio + PyAudio
  2. (optional) Install the latest Brew supported for Mac m1 using the command on the Brew homepage (可选)使用 Brew 主页上的命令安装支持 Mac m1 的最新 Brew
  3. (optional) Install wheel and setuptools: python3 -m pip install --upgrade pip setuptools wheel (可选)安装 wheel 和 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安装最新版本的portaudio(我相信这是核心问题,稳定版19.6.0没用):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"使用 pip 安装 PyAudio:python3 -m pip install pyaudio --global-option="build_ext" --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/库”

Restart terminal might help if things did not go well.如果事情没有 go 好,重新启动终端可能会有所帮助。

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在 Rosetta 下运行

  2. Install homebrew as intel-based version安装 homebrew 作为基于 intel 的版本

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.我们现在可以使用基于英特尔的自制软件安装的 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

While troubleshooting the same (including following the steps from momoclouq's answer on this question) I ran into this error as well.在对相同问题进行故障排除时(包括按照 momoclouq 对这个问题的回答中的步骤),我也遇到了这个错误。 My final solution was:我的最终解决方案是:

My homebrew was only installed in /usr/local which is for rosetta-emulated (Intel) code.我的自制软件仅安装在 /usr/local 中,用于罗塞塔仿真(英特尔)代码。 See more information in this Stackoverflow question/answer.这个Stackoverflow 问题/答案中查看更多信息。

Once I had the correct homebrew installation for ARM64 under /opt/homebrew I removed my previous portaudio installation and did the following:一旦我在/opt/homebrew下为 ARM64 安装了正确的 homebrew,我就删除了之前的 portaudio 安装并执行了以下操作:

  • $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. $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确保此路径与您的 arch arm64 portaudio 安装一致。

The first answer was helpful, but global-option doesn't work anymore, so here's an updated sequence of commands:第一个答案很有帮助,但 global-option 不再起作用,所以这里有一个更新的命令序列:

(I ran this on a Mac M1) (我在 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://stackoverflow.com/a/73930804/4656769 https://stackoverflow.com/a/73930804/4656769

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

相关问题 无法导入 PyAudio C 模块“_portaudio”。 (Mac M1),关于找不到符号:_PaMacCore_SetupChannelMap - Could not import the PyAudio C module '_portaudio'. (Mac M1), about Symbol not found: _PaMacCore_SetupChannelMap 未找到PortAudio符号:Mountain Lion上的_PaMacCore_SetupChannelMap - PortAudio Symbol not found: _PaMacCore_SetupChannelMap on Mountain Lion Mac M1(Apple Silicon)上的 AWS SAM Python 调试 - AWS SAM Python debug on Mac M1 (Apple Silicon) Mac M1 无法安装 PyAudio - Mac M1 Can't Install PyAudio 使用 docker 在苹果硅 M1 上构建错误 - Build Error on apple silicon M1 with docker 无法在 Apple Silicon 上导入 pyodbc - 找不到符号:_SQLAllocHandle - Unable to import pyodbc on Apple Silicon - Symbol not found: _SQLAllocHandle 在具有 M1 芯片(基于 ARM 的 Apple Silicon)的 Mac 上安装早期版本的 Python(3.8 之前)失败 - Installation of earlier versions of Python (prior to 3.8) fails on Mac with M1 Chip (ARM based Apple Silicon) Apple Silicon M1 上的 Python Tensorflow 和 OpenCV - Python Tensorflow and OpenCV on Apple Silicon M1 如何在M1(Apple Silicon / Darwin-arm64)上安装和导入Scipy、Numpy、NumExpr等? - How to install and import Scipy, Numpy, NumExpr and others on M1 (Apple Silicon / Darwin-arm64)? 带有 macOS Big Sur 11.2.1 的苹果 m1 安装软件失败,出现终止错误 - apple m1 with macOS Big Sur 11.2.1 install soft faild, with killed error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM