我有一台M1 Mac。使用基于英特尔的dmg时,我的程序在PyCharm中运行良好。PyCharm不断通知我升级到针对Apple Silicon优化的版本。PyCharm打开时明显平滑。但是现在运行我的脚本会给我一个ImportError为sounddevice"图书馆。我尝试了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
默认情况下,pip install
安装了最新版本(截至本文发布时,版本为0.4.5)
python3 -m pip install sounddevice
文档说明0.4.3版本添加了"通用".dylib for macOs: 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