简体   繁体   English

在 PyCharm(不兼容的架构)中运行脚本时,M1 Mac 上“sounddevice”的 Python ImportError

[英]Python ImportError of "sounddevice" on M1 Mac when running script in PyCharm (incompatible architecture)

I have an M1 Mac.我有一台 M1 Mac。 My program was running fine in PyCharm when using the Intel-based dmg.使用基于 Intel 的 dmg 时,我的程序在 PyCharm 中运行良好。 PyCharm kept notifying me to upgrade to the version optimized for Apple Silicon. PyCharm 一直通知我升级到针对 Apple Silicon 优化的版本。 PyCharm opened noticeably smoother. PyCharm 打开明显更流畅。 But trying to run my script now gives me an ImportError for "sounddevice" library.但是现在尝试运行我的脚本会给我一个“sounddevice”库的 ImportError。 I tried to pip uninstall/reinstall, but made no difference.我尝试 pip 卸载/重新安装,但没有任何区别。 How can I fix this?我怎样才能解决这个问题?

Traceback (most recent call last):
  File "/Users/anonymous/PycharmProjects/ChineseTranscriber/main.py", line 2, in <module>
    import sounddevice
  File "/Users/anonymous/PycharmProjects/ChineseTranscriber/venv/lib/python3.9/site-packages/sounddevice.py", line 58, in <module>
    from _sounddevice import ffi as _ffi
  File "/Users/anonymous/PycharmProjects/ChineseTranscriber/venv/lib/python3.9/site-packages/_sounddevice.py", line 2, in <module>
    import _cffi_backend
ImportError: dlopen(/Users/anonymous/PycharmProjects/ChineseTranscriber/venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so, 0x0002): tried: '/Users/anonymous/PycharmProjects/ChineseTranscriber/venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/anonymous/PycharmProjects/ChineseTranscriber/venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so' (no such file), '/Users/anonymous/PycharmProjects/ChineseTranscriber/venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

Process finished with exit code 1

By default, pip install installed the latest version (as of the time of this post, version 0.4.5)默认情况下, pip install安装了最新版本(截至本文发布时,版本为 0.4.5)

python3 -m pip install sounddevice

Documentation states that version 0.4.3 added the a "universal".dylib for macOs: https://readthedocs.org/projects/python-sounddevice/downloads/pdf/latest/文档指出版本 0.4.3 添加了适用于 macO 的“通用”.dylib: https ://readthedocs.org/projects/python-sounddevice/downloads/pdf/latest/

However, version 0.4.5 seemed to unintendedly revert/negatively affect the necessary change in 0.4.3.然而,版本 0.4.5 似乎无意中恢复/负面影响了 0.4.3 中的必要更改。

Uninstalling sounddevice and specifying the reinstall to use version 0.4.3 fixed the issue卸载 sounddevice 并指定重新安装以使用版本 0.4.3 解决了这个问题

python3 -m pip uninstall sounddevice
python3 -m pip install -Iv sounddevice==0.4.3

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

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