Databricks Machine Learning Associate Question 42
Single answerYou are working on a shared Databricks cluster and need to install a Python library so that it is available to all notebooks running on this cluster. Which of the following is the correct method to achieve this?
- A
Use
%pip install <library-name>in the first cell of all notebooks on the cluster. - B
Install the library via the Libraries tab in the Cluster configuration page.
- C
Use the
dbutils.library.installcommand in one notebook, and it will automatically apply to the cluster. - D
Run
%conda install <library-name>in a notebook which will install it for the cluster.
Show answer and explanation
Correct answer: B
Explanation
To make a Python library available to all notebooks on a Databricks cluster, you must install it via the Libraries tab in the Cluster configuration page. This ensures that the library is installed at the cluster level and is accessible to all notebooks that use the cluster. Notebook-specific commands like %pip install only install the library for the current notebook session and do not propagate the installation to all other notebooks on the cluster.
- A. Incorrect.
Using
%pip install <library-name>installs the library only for the current notebook session. It does not make the library available to all notebooks on the cluster. - B. Correct.
Installing the library via the Libraries tab in the Cluster configuration page ensures the library is installed at the cluster level and is available to all notebooks running on the cluster.
- C. Incorrect.
dbutils.library.installis not a valid method for installing libraries in a Databricks environment. This option is incorrect. - D. Incorrect.
%conda is not supported in Databricks for library installation. Libraries should be installed using
%pipor the Libraries tab in the Cluster configuration page.