Install dependencies

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

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

Install dependencies from a notebook

Python packages

To install Python packages from a notebook:

  1. Go to the AI Platform Notebooks page in the Google Cloud Platform Console.

    Go to the AI Platform Notebooks page

  2. Select Open JupyterLab for the Python instance where you want to install dependencies.

  3. Select File -> New -> Notebook. This creates a new notebook named "Untitled.ipynb." Select the kernel for your new notebook. For example, "Python 3." You can also create a Python notebook using the Launcher.

    Add a notebook file

  4. Select File -> Rename notebook and change the name of the untitled notebook to something meaningful, such as "install.ipynb."

  5. When you open your new notebook, there is a default code cell where you can enter code, in this case Python 3, to install dependencies. For example, to install the mxnet deep learning library in a Python 3 notebook, enter the following in the code cell: %pip install mxnet. To install the library in a Python 2 notebook, enter the following: !pip2 install mxnet.

    Add code to a notebook cell

  6. Press the run button to run the install command.

    Press run button

  7. When installation is complete, 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.

R packages

To install R packages from a notebook:

  1. Go to the AI Platform Notebooks page in the Google Cloud Platform Console.

    Go to the AI Platform Notebooks page

  2. Select Open JupyterLab for the R instance where you want to install dependencies.

  3. Select File -> New -> Notebook. This creates a new notebook named "Untitled.ipynb." Select the "R" kernel for your new notebook. You can also create an R notebook using the Launcher.

    Add a notebook file

  4. Select File -> Rename notebook and change the name of the untitled notebook to something meaningful, such as "install.ipynb."

  5. When you open your new notebook, there is a default code cell where you can enter code, in this case R, to install dependencies. For example, to install the deepnet deep learning neural network package in an R notebook, enter the following in the code cell: install.packages("deepnet").

    Add code to a notebook cell

  6. Press the run button to run the install command.

    Press run button

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

Install dependencies from a terminal

Python packages

To install Python packages from a terminal:

  1. Go to the AI Platform Notebooks page in the Google Cloud Platform Console.

    Go to the AI Platform Notebooks page

  2. Select Open JupyterLab for the Python instance where you want to install dependencies.

  3. Select File -> New -> Terminal to open a terminal window. You can also open a terminal window using the Launcher.

    Open a terminal window

  4. In the terminal window, enter the command to install the software dependency for your notebook instance. For example, to install the mxnet deep learning library for Python 3 notebooks, enter the following command: pip3 install mxnet. For Python 2 notebooks, enter: pip2 install mxnet.

  5. In any open Python notebooks, you may need to select Kernel -> Restart Kernel to restart the kernel and ensure the library is available for import.

R packages

To install R packages from a terminal:

  1. Go to the AI Platform Notebooks page in the Google Cloud Platform Console.

    Go to the AI Platform Notebooks page

  2. Select Open JupyterLab for the R instance where you want to install dependencies.

  3. Select File -> New -> Terminal to open a terminal window. You can also open a terminal window using the Launcher.

    Open a terminal window

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

  5. At the R prompt, enter the command to install the software dependency for your notebook instance. For example, to install the deepnet deep learning neural network package, enter the following command: install.packages("deepnet").

¿Te sirvió esta página? Envíanos tu opinión:

Enviar comentarios sobre…