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

w41d8nur  于 2022-12-23  发布在  PyCharm
关注(0)|答案(1)|浏览(335)

我有一台M1 Mac。当使用基于Intel的dmg时,我的程序在PyCharm中运行良好。PyCharm不断通知我升级到针对Apple Silicon优化的版本。PyCharm打开时明显更流畅。但现在尝试运行脚本时,“sounddevice”库出现ImportError。我尝试pip卸载/重新安装,但没有任何区别。我如何修复此问题?

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
uujelgoq

uujelgoq1#

默认情况下,pip install安装了最新版本(截至本文发表时,版本为0.4.5)

python3 -m pip install sounddevice

文档指出,版本0.4.3为macOs添加了一个“通用”.dylib:https://readthedocs.org/projects/python-sounddevice/downloads/pdf/latest/
然而,版本0.4.5似乎无意中恢复了0.4.3中的必要变更/对其产生了负面影响。
卸载sounddevice并指定重新安装以使用版本0.4.3修复了此问题

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

相关问题