Install dependencies

After you create a user-managed notebooks instance, you might need to install software that your notebook depends on. You can install dependencies by adding install commands to a file in your notebook or by using a terminal window.

An advantage of adding install commands to a file is that, when you share a notebook, the commands to install the dependencies are saved with the notebook and are available to users that you share the notebook with.

Install dependencies from a user-managed notebooks instance

To install Python packages from a user-managed notebooks instance:

  1. In the Google Cloud console, go to the User-managed notebooks page.

    Go to User-managed notebooks

  2. Select the instance where you want to install dependencies.

  3. Click Open JupyterLab.

  4. To add a notebook file, you can use the menu or the Launcher.

    1. To add a new notebook file from the menu, select File > New > Notebook.

      Add a notebook file.

    2. In the Select kernel dialog, select the kernel for your new notebook, for example, Python 3, and then click Select.

      Your new notebook file opens.

    Launcher

    1. To add a new Python 3 notebook file from the Launcher, select File > New > Launcher.

    2. Click the Python 3 tile.

      Add a notebook file.

      Your new notebook file opens.

  5. Rename your new notebook file.

    1. Select File > Rename notebook. The Rename file dialog opens.

    2. In the New name field, change Untitled.ipynb to something meaningful, such as install.ipynb.

    3. Click Rename.

    Launcher

    1. Right-click the Untitled.ipynb tab and then click Rename notebook. The Rename file dialog opens.

    2. In the New name field, change Untitled.ipynb to something meaningful, such as install.ipynb.

    3. Click Rename.

  6. Install dependencies as follows.

    When you open your new notebook, there is a default code cell where you can enter code, in this case Python 3.

    To install the mxnet deep learning library in a Python 3 notebook, enter the following command in the code cell:

    %pip install mxnet

    Add code to a notebook cell.

  7. Click the run button to run the install command.

    Click the run button.

  8. When installation is complete, select Kernel > Restart kernel to restart the kernel and ensure the library is available for import.

  9. Select File > Save notebook to save the notebook.

Install dependencies from a terminal

To connect to a terminal, you can use your JupyterLab notebook or SSH. To install Python packages from a terminal:

  1. In the Google Cloud console, go to the User-managed notebooks page.

    Go to User-managed notebooks

  2. Select the instance where you want to install dependencies.

  3. Click Open JupyterLab.

  4. To open a terminal window, you can use the menu or the Launcher.

    To open a terminal window from the menu, select File > New > Terminal.

    Open terminal.

    The terminal window opens.

    Launcher

    1. To open a terminal window from the Launcher, select File > New > Launcher.

    2. In Other, click the Terminal tile.

      Open terminal.

      The terminal window opens.

  5. In the terminal window, enter the command to install the software dependency for your user-managed notebooks instance.

    To install the mxnet deep learning library for Python 3 notebooks, enter the following command:

    pip3 install mxnet

    Add code to a terminal.

  6. When installation is complete, restart the kernel to make sure the library is available for import. In every open notebook file in the same user-managed notebooks instance, select Kernel > Restart kernel.

  7. Select File > Save notebook to save the notebook.