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: cannot load library #324

Open
Fograd opened this issue Jan 21, 2022 · 4 comments
Open

OSError: cannot load library #324

Fograd opened this issue Jan 21, 2022 · 4 comments

Comments

@Fograd
Copy link

Fograd commented Jan 21, 2022

Hey there, first of all, I am not a programmer. I just need to run a program that has been sent to me and uses the soundfile library.

I have installed soundfile using pip (I am on Mac M1, using PyCharm as IDE, python 3.10.2) but when I run my program, I get this error:

File "/Users/mehradmansoubi/PycharmProjects/multi/venv/lib/python3.10/site-packages/soundfile.py", line 162, in <module> _snd = _ffi.dlopen(_os.path.join( OSError: cannot load library '/Users/mehrad/PycharmProjects/multi/venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/Users/mehrad/PycharmProjects/multi/venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib, 0x0002): tried: '/Users/mehrad/PycharmProjects/multi/venv/lib/python3.10/site-packages/_soundfile_data/libsndfile.dylib' (no such file), '/usr/lib/libsndfile.dylib' (no such file)

where can I get this "libsndfile.dylib" and I am assuming, other missing files to get it to work? I read in some other issue that the problem is from pip 20. I downgraded it to a lower pip and it still does not work.

Could anyone please, in a simple non-programmer language explain what the issue is and how I can resolve it? thank you <3

@bastibe
Copy link
Owner

bastibe commented Jan 23, 2022

There's a fix for this in #310, but I haven't gotten around to publishing the bugfix yet. There's a related bugfix in #322 that needs to be included, too.

@williamarchbold
Copy link

williamarchbold commented Oct 23, 2022

any update to this? I just raan into the same thing with python 3.10.8
"name": "OSError",
"message": "cannot load library '/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib, 0x0002): tried: '/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib' (no such file). Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib'",
"stack": "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/soundfile.py:267\u001b[0m, in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 266\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 267\u001b[0m _snd \u001b[39m=\u001b[39m _ffi\u001b[39m.\u001b[39;49mdlopen(\u001b[39m'\u001b[39;49m\u001b[39msndfile\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[1;32m 268\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mOSError\u001b[39;00m:\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/cffi/api.py:150\u001b[0m, in \u001b[0;36mFFI.dlopen\u001b[0;34m(self, name, flags)\u001b[0m\n\u001b[1;32m 149\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_lock:\n\u001b[0;32m--> 150\u001b[0m lib, function_cache \u001b[39m=\u001b[39m _make_ffi_library(\u001b[39mself\u001b[39;49m, name, flags)\n\u001b[1;32m 151\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_function_caches\u001b[39m.\u001b[39mappend(function_cache)\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/cffi/api.py:832\u001b[0m, in \u001b[0;36m_make_ffi_library\u001b[0;34m(ffi, libname, flags)\u001b[0m\n\u001b[1;32m 831\u001b[0m backend \u001b[39m=\u001b[39m ffi\u001b[39m.\u001b[39m_backend\n\u001b[0;32m--> 832\u001b[0m backendlib \u001b[39m=\u001b[39m _load_backend_lib(backend, libname, flags)\n\u001b[1;32m 833\u001b[0m \u001b[39m#\u001b[39;00m\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/cffi/api.py:827\u001b[0m, in \u001b[0;36m_load_backend_lib\u001b[0;34m(backend, name, flags)\u001b[0m\n\u001b[1;32m 826\u001b[0m msg \u001b[39m=\u001b[39m \u001b[39m"\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m. Additionally, \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m"\u001b[39m \u001b[39m%\u001b[39m (first_error, msg)\n\u001b[0;32m--> 827\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mOSError\u001b[39;00m(msg)\n\u001b[1;32m 828\u001b[0m \u001b[39mreturn\u001b[39;00m backend\u001b[39m.\u001b[39mload_library(path, flags)\n\n\u001b[0;31mOSError\u001b[0m: ctypes.util.find_library() did not manage to locate a library called 'sndfile'\n\nDuring handling of the above exception, another exception occurred:\n\n\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)\n\u001b[1;32m/Users/William/Development/CS5930_MachineLearning/Project/WorkArea/guitarAI.ipynb Cell 1\u001b[0m in \u001b[0;36m<cell line: 46>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 41\u001b[0m seed(\u001b[39m1\u001b[39m)\n\u001b[1;32m 42\u001b[0m \u001b[39m#set_random_seed(2)\u001b[39;00m\n\u001b[1;32m 43\u001b[0m \n\u001b[1;32m 44\u001b[0m \u001b[39m# Audio\u001b[39;00m\n\u001b[1;32m 45\u001b[0m \u001b[39m#import librosa.display\u001b[39;00m\n\u001b[0;32m---> 46\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mlibrosa\u001b[39;00m \n\u001b[1;32m 48\u001b[0m \u001b[39m#import ffmpeg\u001b[39;00m\n\u001b[1;32m 49\u001b[0m \n\u001b[1;32m 50\u001b[0m \u001b[39m# Configurations\u001b[39;00m\n\u001b[1;32m 51\u001b[0m path\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mphilharmonic-samples/\u001b[39m\u001b[39m'\u001b[39m\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/librosa/init.py:209\u001b[0m, in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 207\u001b[0m \u001b[39m# And all the librosa sub-modules\u001b[39;00m\n\u001b[1;32m 208\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39m_cache\u001b[39;00m \u001b[39mimport\u001b[39;00m cache\n\u001b[0;32m--> 209\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m \u001b[39mimport\u001b[39;00m core\n\u001b[1;32m 210\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m \u001b[39mimport\u001b[39;00m beat\n\u001b[1;32m 211\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m \u001b[39mimport\u001b[39;00m decompose\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/librosa/core/init.py:6\u001b[0m, in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[39m""" Core IO and DSP functions"""\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mconvert\u001b[39;00m \u001b[39mimport\u001b[39;00m \u001b[39m*\u001b[39m \u001b[39m# pylint: disable=wildcard-import\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39maudio\u001b[39;00m \u001b[39mimport\u001b[39;00m \u001b[39m*\u001b[39m \u001b[39m# pylint: disable=wildcard-import\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mspectrum\u001b[39;00m \u001b[39mimport\u001b[39;00m \u001b[39m*\u001b[39m \u001b[39m# pylint: disable=wildcard-import\u001b[39;00m\n\u001b[1;32m 8\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39m.\u001b[39;00m\u001b[39mpitch\u001b[39;00m \u001b[39mimport\u001b[39;00m \u001b[39m*\u001b[39m \u001b[39m# pylint: disable=wildcard-import\u001b[39;00m\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/librosa/core/audio.py:8\u001b[0m, in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpathlib\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mwarnings\u001b[39;00m\n\u001b[0;32m----> 8\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39msoundfile\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39msf\u001b[39;00m\n\u001b[1;32m 9\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39maudioread\u001b[39;00m\n\u001b[1;32m 10\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mnumpy\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mnp\u001b[39;00m\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/soundfile.py:276\u001b[0m, in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 274\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 275\u001b[0m \u001b[39mraise\u001b[39;00m\n\u001b[0;32m--> 276\u001b[0m _snd \u001b[39m=\u001b[39m _ffi\u001b[39m.\u001b[39;49mdlopen(_os\u001b[39m.\u001b[39;49mpath\u001b[39m.\u001b[39;49mjoin(\n\u001b[1;32m 277\u001b[0m os\u001b[39m.\u001b[39;49mpath\u001b[39m.\u001b[39;49mdirname(os\u001b[39m.\u001b[39;49mpath\u001b[39m.\u001b[39;49mabspath(\u001b[39m__file\u001b[39;49m)),\n\u001b[1;32m 278\u001b[0m \u001b[39m'\u001b[39;49m\u001b[39m_soundfile_data\u001b[39;49m\u001b[39m'\u001b[39;49m, _libname))\n\u001b[1;32m 280\u001b[0m libsndfile_version \u001b[39m=\u001b[39m _ffi\u001b[39m.\u001b[39mstring(_snd\u001b[39m.\u001b[39msf_version_string())\u001b[39m.\u001b[39mdecode(\u001b[39m'\u001b[39m\u001b[39mutf-8\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mreplace\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m 281\u001b[0m \u001b[39mif\u001b[39;00m libsndfile_version\u001b[39m.\u001b[39mstartswith(\u001b[39m'\u001b[39m\u001b[39mlibsndfile-\u001b[39m\u001b[39m'\u001b[39m):\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/cffi/api.py:150\u001b[0m, in \u001b[0;36mFFI.dlopen\u001b[0;34m(self, name, flags)\u001b[0m\n\u001b[1;32m 147\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39m"\u001b[39m\u001b[39mdlopen(name): name must be a file name, None, \u001b[39m\u001b[39m"\u001b[39m\n\u001b[1;32m 148\u001b[0m \u001b[39m"\u001b[39m\u001b[39mor an already-opened \u001b[39m\u001b[39m'\u001b[39m\u001b[39mvoid *\u001b[39m\u001b[39m'\u001b[39m\u001b[39m handle\u001b[39m\u001b[39m"\u001b[39m)\n\u001b[1;32m 149\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_lock:\n\u001b[0;32m--> 150\u001b[0m lib, function_cache \u001b[39m=\u001b[39m _make_ffi_library(\u001b[39mself\u001b[39;49m, name, flags)\n\u001b[1;32m 151\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_function_caches\u001b[39m.\u001b[39mappend(function_cache)\n\u001b[1;32m 152\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_libraries\u001b[39m.\u001b[39mappend(lib)\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/cffi/api.py:832\u001b[0m, in \u001b[0;36m_make_ffi_library\u001b[0;34m(ffi, libname, flags)\u001b[0m\n\u001b[1;32m 830\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_make_ffi_library\u001b[39m(ffi, libname, flags):\n\u001b[1;32m 831\u001b[0m backend \u001b[39m=\u001b[39m ffi\u001b[39m.\u001b[39m_backend\n\u001b[0;32m--> 832\u001b[0m backendlib \u001b[39m=\u001b[39m _load_backend_lib(backend, libname, flags)\n\u001b[1;32m 833\u001b[0m \u001b[39m#\u001b[39;00m\n\u001b[1;32m 834\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39maccessor_function\u001b[39m(name):\n\nFile \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/cffi/api.py:827\u001b[0m, in \u001b[0;36m_load_backend_lib\u001b[0;34m(backend, name, flags)\u001b[0m\n\u001b[1;32m 825\u001b[0m \u001b[39mif\u001b[39;00m first_error \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 826\u001b[0m msg \u001b[39m=\u001b[39m \u001b[39m"\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m. Additionally, \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m"\u001b[39m \u001b[39m%\u001b[39m (first_error, msg)\n\u001b[0;32m--> 827\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mOSError\u001b[39;00m(msg)\n\u001b[1;32m 828\u001b[0m \u001b[39mreturn\u001b[39;00m backend\u001b[39m.\u001b[39mload_library(path, flags)\n\n\u001b[0;31mOSError\u001b[0m: cannot load library '/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib, 0x0002): tried: '/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib' (no such file). Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/William/Library/Python/3.10/lib/python/site-packages/_soundfile_data/libsndfile.dylib'"
}

@bastibe
Copy link
Owner

bastibe commented Oct 23, 2022

You should have an up-to-date pip and wheel, and then pip install soundfile, to get the proper wheel. Otherwise, install libsndfile using e.g. brew.

@williamarchbold
Copy link

is 0.11 soundfile the latest?

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

3 participants