30

I have been working with a python program which uses sounddevice module to play audio. The program works fine in my office pc (running Ubuntu 17.10), but not in my home pc (running Linux Mint 18.3). It generates the following error:

Traceback (most recent call last):
  File "...path/to/my/code.py", line 11, in <module>
    import sounddevice as sd
  File "/home/arif/anaconda3/lib/python3.6/site-packages/sounddevice.py", line 64, in <module>
    raise OSError('PortAudio library not found')
OSError: PortAudio library not found 

How can I fix this problem?

Arif Ahmad
  • 403
  • 1
  • 6
  • 6
  • Did you install PortAudio? See [the documentation](http://python-sounddevice.readthedocs.io/en/0.3.10/#requirements). – Matthias Mar 18 '18 at 08:43
  • @Matthias Yes, everything was installed accordingly. I've just noticed that, my script is running on Jupyter Notebook but not on PyCharm. – Arif Ahmad Mar 19 '18 at 04:32
  • The `sounddevice` module does this: `from ctypes.util import find_library; find_library('portaudio')`. If this returns `None`, your error appears. – Matthias Mar 19 '18 at 08:55
  • I figured that too. Can you point out any reason why is it returning `None`? – Arif Ahmad Mar 19 '18 at 12:12
  • If you figured that, you should probably mention it in your updated question. As for why it might be returning `None`, see the [docs](https://docs.python.org/3/library/ctypes.html#finding-shared-libraries). – Matthias Mar 19 '18 at 16:01

2 Answers2

77

I could fix this by installing the portaudio library.

sudo apt-get install libportaudio2

You may also try following if this doesn't help.

sudo apt-get install libasound-dev
Anubis
  • 6,995
  • 14
  • 56
  • 87
  • 2
    The first one fixes the issues on ubuntu 19.4 – thisshri Nov 24 '19 at 17:56
  • 1
    what does the second line do? Is it a dependency? I didn't see that package listed when I ran the first line. – rfii Jul 17 '20 at 21:38
  • I think the second line has to do with numpy installations not working properly on raspberry pis. Numpy came with sounddevice, but these instructions say that second line is required to fix a numpy problem: `https://numpy.org/devdocs/user/troubleshooting-importerror.html` – rfii Jul 17 '20 at 22:12
  • 1
    fix in wsl2 as well – CircleOnCircles Aug 01 '21 at 19:39
0

I have Rocky Linux 9, which is based on RHEL. I also fixed that by installing the portaudio package via this command:

dnf install portaudio portaudio-devel

It might be useful for Rocky Linux users.