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

Python packages

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

  1. In the Google Cloud Console, go to the Notebooks page.

    Go to Notebooks

  2. On the User-managed notebooks tab, 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.

R packages

To install R packages from a notebook:

  1. In the Google Cloud Console, go to the Notebooks page.

    Go to Notebooks

  2. On the User-managed notebooks tab, 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 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, R, and then click Select.

    Your new notebook file opens.

    Launcher

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

    2. Click the R 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 R.

    To install the deepnet deep learning neural network package in an R notebook, enter the following command in the code cell:

    install.packages("deepnet")

    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. The following information shows how to use your JupyterLab notebook to connect to a terminal.

Python packages

To install Python packages from a terminal:

  1. In the Google Cloud Console, go to the Notebooks page.

    Go to Notebooks

  2. On the User-managed notebooks tab, 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, go to any open Python notebooks and select Kernel > Restart kernel to restart the kernel and ensure the library is available for import.

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

R packages

To install R packages from a terminal:

  1. In the Google Cloud Console, go to the Notebooks page.

    Go to Notebooks

  2. Make sure the User-managed notebooks tab is selected.

  3. Next to your user-managed notebooks R instance where you want to install dependencies, 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.

    The terminal window opens.

    Open terminal.

    Launcher

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

    2. In Other, click the Terminal tile.

    The terminal window opens.

    Open terminal.

  5. In the terminal window, enter R to go to the R prompt.

  6. At the R prompt, enter the command to install the software dependency for your user-managed notebooks instance.

    To install the deepnet deep learning neural network package, enter the following command:

    install.packages("deepnet")

    Add code to a terminal.

  7. When installation is complete, go to any open Python notebooks and select Kernel > Restart kernel to restart the kernel and ensure the library is available for import.

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