Use Script Action to install external Python packages for Jupyter notebooks in Apache Spark clusters on HDInsight

Learn how to use Script Actions to configure an Apache Spark cluster on HDInsight (Linux) to use external, community-contributed python packages that are not included out-of-the-box in the cluster.


You can also configure a Jupyter notebook by using %%configure magic to use external packages. For instructions, see Use external packages with Jupyter notebooks in Apache Spark clusters on HDInsight.

You can search the package index for the complete list of packages that are available. You can also get a list of available packages from other sources. For example, you can install packages made available through Anaconda or conda-forge.

In this article, you will learn how to install the TensorFlow package using Script Action on your cluster and use it via the Jupyter notebook.


You must have the following:

Use external packages with Jupyter notebooks

  1. From the Azure Portal, from the startboard, click the tile for your Spark cluster (if you pinned it to the startboard). You can also navigate to your cluster under Browse All > HDInsight Clusters.

  2. From the Spark cluster blade, click Script Actions from the left pane. Run the custom action that installs TensorFlow in the head nodes and the worker nodes. The bash script can be referenced from: Visit the documentation on how to use custom script actions.


    There are two python installations in the cluster. Spark will use the Anaconda python installation located at /usr/bin/anaconda/bin. Reference that installation in your custom actions via /usr/bin/anaconda/bin/pip and /usr/bin/anaconda/bin/conda.

  3. Open a PySpark Jupyter notebook

    Create a new Jupyter notebook

  4. A new notebook is created and opened with the name Untitled.pynb. Click the notebook name at the top, and enter a friendly name.

    Provide a name for the notebook

  5. You will now import tensorflow and run a hello world example.

    Code to copy:

     import tensorflow as tf
     hello = tf.constant('Hello, TensorFlow!')
     sess = tf.Session()

    The result will look like this:

    TensorFlow code execution

See also


Create and run applications

Tools and extensions

Manage resources