0

I have an M1 Mac. My program was running fine in PyCharm when using the Intel-based dmg. PyCharm kept notifying me to upgrade to the version optimized for Apple Silicon. PyCharm opened noticeably smoother. But trying to run my script now gives me an ImportError for "sounddevice" library. I tried to pip uninstall/reinstall, but made no difference. 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
Frant
  • 5,382
  • 1
  • 16
  • 22
nhershy
  • 643
  • 1
  • 6
  • 20
  • Like the error message says, you have installed an `x86_64` package but your CPU is an `arm64` – tripleee Dec 22 '22 at 17:23
  • But is there an arm64 version for this module? Or a way to convert the current package to work for arm64? – nhershy Dec 22 '22 at 17:35
  • Convert, no. Install one for the correct architecture. This begs the question how you managed to install the package for the wrong architecture in the first place; `pip` will generally refuse. – tripleee Dec 22 '22 at 17:37
  • 1
    I got it. See answer if you're curious – nhershy Dec 22 '22 at 17:48
  • The error message talks about `_cffi_backend`, which is part of the `cffi` package, which supposedly has macOS arm64 support since version 1.15.0 (https://cffi.readthedocs.io/en/latest/whatsnew.html#v1-15-0). – Matthias Dec 24 '22 at 08:04

1 Answers1

0

By default, pip install installed the latest version (as of the time of this post, version 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/

However, version 0.4.5 seemed to unintendedly revert/negatively affect the necessary change in 0.4.3.

Uninstalling sounddevice and specifying the reinstall to use version 0.4.3 fixed the issue

python3 -m pip uninstall sounddevice
python3 -m pip install -Iv sounddevice==0.4.3
nhershy
  • 643
  • 1
  • 6
  • 20
  • I don't think this has anything to do with the version of `sounddevice`, I suspect you just happened to install the newest version of `cffi` the second time, which now happens to support `arm64`. – Matthias Dec 24 '22 at 08:07