spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
1.02k stars 149 forks source link

Sounddevice isnt detecting portaudio on my MacBook | OSError: PortAudio library not found | #363

Closed fvviz closed 2 years ago

fvviz commented 3 years ago

When i run this code

import sounddevice

i get this error

Traceback (most recent call last):
  File "/Users/faizrahim/PycharmProjects/voice-lag-simul/venv/lib/python3.8/site-packages/sounddevice.py", line 71, in <module>
    raise OSError('PortAudio library not found')
OSError: PortAudio library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/faizrahim/PycharmProjects/voice-lag-simul/writejson.py", line 1, in <module>
    import sounddevice
  File "/Users/faizrahim/PycharmProjects/voice-lag-simul/venv/lib/python3.8/site-packages/sounddevice.py", line 80, in <module>
    import _sounddevice_data
ModuleNotFoundError: No module named '_sounddevice_data'

This is how i installed sounddevice

pip3 install sounddevice

But I'm sure i installed portaudio on my mac. Even Pyaudio seems to work fine but sounddevice is not working, What can i do now?

mgeier commented 3 years ago

Do you happen to use an M1 processor?

The .dylib shipped with the sounddevice module currently doesn't support that (see https://github.com/spatialaudio/portaudio-binaries/issues/9).

If you are using Homebrew, you can try brew install portaudio.

CatherineHenry commented 3 years ago

I'm seeing the same as OP and am running on an M1 Mac.

~I do have portaudio installed via brew and have tried running pip3 install --no-cache-dir --global-option='build_ext' --global-option='-I/usr/local/opt/portaudio/include' --global-option='-L/usr/local/opt/portaudio/lib' sounddevice but no success thus far~

Update:

I ended up manually creating the path _sounddevice_data/portaudio-binaries/ under <..>/lib/python3.8/site-packages/sounddevice-0.4.2-py3.8.egg/ and copying the values from portaudio lib.

Note: Make sure brew installs were done w/ arch -arm64 or you'll see an architecture mismatch.

mgeier commented 2 years ago

Can someone please check if the .dylib from https://github.com/spatialaudio/portaudio-binaries/pull/10 works properly on an M1 Mac?

mgeier commented 2 years ago

Since there hasn't been any feedback, I've decided to publish a new release anyway (version 0.4.3). Please let me know whether or not that fixes the problem!

fab-jul commented 2 years ago

I'm still getting the error, on an Intel Macbook w/ 11.4. I tried the brew install portaudio --HEAD trick mentioned in various places without luck. My sounddevice version seems to be 0.4.3.

fab-jul commented 2 years ago

I never saw any permissions pop up, is there a way to force this? And also, fyi, I'm using Python 3.10

fab-jul commented 2 years ago

Update: fixed by downgrading to Python 3.8. Maybe some other issue was present. I did now create a few conda env, and then used pip to install sounddevice.