Databricks Certified Machine Learning Associate · Free Practice Question Medium
Question 8
A machine learning team wants to use the Python library newpackage on all of their projects. They share a cluster for all of their projects.
Which approach makes the Python library newpackage available to all notebooks run on a cluster?
-
A
Edit the cluster to use the Databricks Runtime for Machine Learning
-
B
Set the runtime-version variable in their Spark session to "ml"
-
C
Running %pip install newpackage once on any notebook attached to the cluster
-
D
Adding /databricks/python/bin/pip install newpackage to the cluster’s bash init script
-
E
There is no way to make the newpackage library available on a cluster
Reveal correct answer
Correct answer: D
Explanation
Correct Answer:
✅ Adding /databricks/python/bin/pip install newpackage to the cluster’s bash init script
Explanation:
To make the newpackage library available to all notebooks on a shared cluster, the best approach is to install it via the cluster’s init script.
Why?
Init scripts run automatically when the cluster starts, ensuring the package is installed for all users and notebooks.
This eliminates the need for reinstalling the package in each session.
Works across all users and all projects using the same cluster.
How to Add an Init Script to a Databricks Cluster
Navigate to Clusters in the Databricks workspace.
Select the cluster you want to modify.
Click Edit and scroll down to Advanced Options → Init Scripts.
Add the following command to install
newpackage:Example Init Script (Bash)
- #!/bin/bash
- /databricks/python/bin/pip install newpackage
Save the changes and restart the cluster.
The package will now be available in all notebooks attached to this cluster.
Why Other Options Are Incorrect?
"Edit the cluster to use the Databricks Runtime for Machine Learning"
Incorrect, because Databricks ML Runtime includes pre-installed ML libraries but does not automatically install custom packages like
newpackage.
"Set the runtime-version variable in their Spark session to 'ml'"
Incorrect, because there is no
runtime-versionvariable in Spark that controls package availability.Databricks runtime selection happens at the cluster level, not in a notebook session.
"Running
%pip install newpackageonce on any notebook attached to the cluster"Incorrect, because installing with
%pip installonly applies to the current session.Once the cluster restarts, the package will be removed, requiring reinstallation.
"There is no way to make the newpackage library available on a cluster"
Incorrect, because Databricks provides multiple ways to install persistent libraries (e.g., init scripts, cluster libraries, workspace libraries).
Final Answer:
✅ Using an init script (/databricks/python/bin/pip install newpackage) ensures the package is installed persistently on the cluster for all users and notebooks.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
