Issue in importing librosa library while using databricks runtime engine 11.2

Chandru
Databricks Partner

I have installed the library via PyPI on the cluster. When we import the package on notebook, getting the following error

import librosa

OSError: cannot load library 'libsndfile.so': libsndfile.so: cannot open shared object file: No such file or directory

-werners-
Esteemed Contributor III

it seems the linux OS is missing the libsndfile package.

This is apparently a dependency of librosa.

This can be done by using an init script:

https://docs.databricks.com/clusters/init-scripts.html#cluster-scoped-init-scripts

View solution in original post

Chandru
Databricks Partner

Thank you werners. Just figured that out and had an init script to sort out the issue. Below steps helped me to solve the issue.

dbutils.fs.mkdirs("dbfs:/cluster-init/scripts/")

dbutils.fs.put("/cluster-init/scripts/libsndfile-install.sh","""

#!/bin/bash

apt-get --yes install libsndfile1

""", True)

and added init script for the cluster as

dbfs:/cluster-init/scripts/libsndfile-install.sh

Flo
New Contributor III

If anybody ends up here after 2024: the init file must now be placed in the workspace for the cluster to accept it.

So in Workspace, use Create/File to create the init script.

Then add it to the cluster config in
Compute - Your cluster - Advanced Config - init scripts