Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio' #126

Open
andresmntr opened this issue Feb 23, 2021 · 10 comments

Comments

@andresmntr
Copy link

Getting this error:

`
OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

When trying to import soundcard into my project.
OS: macOS

Any idea on how I can solve that?

@bastibe
Copy link
Owner

bastibe commented Feb 24, 2021

What version of macOS and Python are your running?

@andresmntr
Copy link
Author

macOS BigSur Version 11.2.1
python 3.8.5

@phoenix-meadowlark
Copy link

Seeing the same issue with the same OS version and python 3.8.6:

Traceback (most recent call last):
  File "sound.py", line 1, in <module>
    import soundcard as sc
  File ".venv/lib/python3.8/site-packages/soundcard/__init__.py", line 11, in <module>
    from soundcard.coreaudio import *
  File ".venv/lib/python3.8/site-packages/soundcard/coreaudio.py", line 16, in <module>
    _ca = _ffi.dlopen('CoreAudio')
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

@andresmntr
Copy link
Author

andresmntr commented Mar 1, 2021

I have solved it temporarily by following these steps

Seeing the same issue with the same OS version and python 3.8.6:

Traceback (most recent call last):
  File "sound.py", line 1, in <module>
    import soundcard as sc
  File ".venv/lib/python3.8/site-packages/soundcard/__init__.py", line 11, in <module>
    from soundcard.coreaudio import *
  File ".venv/lib/python3.8/site-packages/soundcard/coreaudio.py", line 16, in <module>
    _ca = _ffi.dlopen('CoreAudio')
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

I have temporarily avoided the error by adding this code in .../lib/python3.8/site-packages/cffi/api.py

    if name=='CoreAudio':
        path='/System/Library/Frameworks/CoreAudio.framework/CoreAudio'
    if name=='AudioUnit':
        path='/System/Library/Frameworks/AudioUnit.framework/AudioUnit'

like so:
solution

Hope it helps

@bastibe
Copy link
Owner

bastibe commented Mar 2, 2021

Does this mean it's a CFFI issue? Or is this a problem in SoundCard?

@GaffaSnobb
Copy link

I have the same issue. @andresmntr's solution worked for me. macOS 11.2.1, Python 3.8.5.

@7ombie
Copy link

7ombie commented Jan 13, 2022

I have the same issue, on Monterey, over six months later :(

@bastibe
Copy link
Owner

bastibe commented Jan 14, 2022

Would anyone with access to a Monterey system like to draft a pull request that works around this issue?

@k1ffx
Copy link

k1ffx commented Dec 14, 2022

There was apparently a long list of Python items that were broken by Mac OS Big Sur, including this issue. See https://bugs.python.org/issue41179 and https://bugs.python.org/issue41100. The "mega-issue" was recently closed with fixes in Python 3.10. I just installed Python 3.10.9 on my Big Sur MacBook Air, and ctypes.util.find_library() now works properly.

Unfortunately, SoundCard on Mac still has issues. microphone.record() returns a zero-filled numpy array. Haven't checked yet if there is already an issue about this opened here.

EDIT: As best as I can tell, in _Recorder, after return from _au.AudioUnitRender(), the code always runs through the "special case if output is silence", which simply returns a zero-filled numpy array. That's as far as I could go with this.

Thanks -

Bruce

@bastibe
Copy link
Owner

bastibe commented Dec 19, 2022

I just installed Python 3.10.9 on my Big Sur MacBook Air, and ctypes.util.find_library() now works properly.

That's very good to hear!

Since I don't have access to a modern Mac, one of you will have to step in with a solution to the silence issue. I have no way of debugging this, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants