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:
In the Google Cloud console, go to the User-managed notebooks page.
Select the instance where you want to install dependencies.
Click Open JupyterLab.
To add a notebook file, you can use the menu or the Launcher.
Menu
To add a new notebook file from the menu, select File > New > Notebook.
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
To add a new Python 3 notebook file from the Launcher, select File > New > Launcher.
Click the Python 3 tile.
Your new notebook file opens.
Rename your new notebook file.
Menu
Select File > Rename notebook. The Rename file dialog opens.
In the New name field, change
Untitled.ipynb
to something meaningful, such asinstall.ipynb
.Click Rename.
Launcher
Right-click the
Untitled.ipynb
tab and then click Rename notebook. The Rename file dialog opens.In the New name field, change
Untitled.ipynb
to something meaningful, such asinstall.ipynb
.Click Rename.
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
Click the run button to run the install command.
When installation is complete, select Kernel > Restart kernel to restart the kernel and ensure the library is available for import.
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:
In the Google Cloud console, go to the User-managed notebooks page.
Select the instance where you want to install dependencies.
Click Open JupyterLab.
To open a terminal window, you can use the menu or the Launcher.
Menu
To open a terminal window from the menu, select File > New > Terminal.
The terminal window opens.
Launcher
To open a terminal window from the Launcher, select File > New > Launcher.
In Other, click the Terminal tile.
The terminal window opens.
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
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.
Select File > Save notebook to save the notebook.