Databricks Machine Learning Associate Question 45
Single answerYou are working on a Databricks cluster and need to install a Python library so it is available to all notebooks running on the cluster. Which approach should you take?
- A
Use the %pip install command inside one of the notebooks
- B
Install the library via the Library tab in the Cluster configuration
- C
Use the dbutils.library.install() command in a notebook
- D
Manually add the library to each notebook using the sys.path.append() function
Show answer and explanation
Correct answer: B
Explanation
The recommended way to install a Python library for all notebooks on a Databricks cluster is to use the Library tab in the Cluster configuration. This ensures the library is installed at the cluster level and is available to all notebooks that run on the cluster. Other methods, like using %pip install or dbutils, are either limited to individual notebooks or unsupported in this context.
- A. Incorrect.
Using %pip install in a notebook only makes the library available to that specific notebook session. This does not ensure availability across all notebooks on the cluster.
- B. Correct.
Installing the library via the Library tab in the Cluster configuration ensures that the library is installed on the cluster and is available to all notebooks running on the cluster.
- C. Incorrect.
The dbutils.library.install() command is not the recommended or supported approach for installing libraries in Databricks, and this method is deprecated.
- D. Incorrect.
Manually adding the library to each notebook using sys.path.append() is not a scalable or practical method for ensuring availability across notebooks on the cluster.