{ "cells": [ { "cell_type": "markdown", "id": "0e83553f-8e7d-4377-b336-78b281e3b90d", "metadata": {}, "source": [ "# Setting up a Custom Environment in SageMaker Studio Lab\n", "This notebook is an example how you can setup a custom environment in SageMaker Studio Lab to install additional packages to your environment." ] }, { "cell_type": "markdown", "id": "fe275517-a1a4-439f-ae78-f9d5d2066eee", "metadata": {}, "source": [ "In this example we are creating a custom environment to do geospatial analysis that includes packages like `geopandas`,`rasterio`, `earthpy` among others." ] }, { "cell_type": "markdown", "id": "602e3d0e-826d-4e91-a03c-67e353575900", "metadata": {}, "source": [ "## Create YAML file\n", "First we create a YAML file with the packages that we want to install in our custom environment. You can also specify how or what package repositories you want to use to use to install these, like via `pip` or `conda`. Once you create the file, make sure you upload to the root of your repository or local folder." ] }, { "cell_type": "markdown", "id": "ff7ba7e6-f926-41b4-9b9c-2312c4a3bb5b", "metadata": {}, "source": [ "The following is an example of a custom YAML file" ] }, { "cell_type": "code", "execution_count": 2, "id": "87cc4128-d305-4e2d-a8ec-c3b614e1f61e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[94mname\u001b[39;49;00m: geospatial\n", "\u001b[94mdependencies\u001b[39;49;00m:\n", " - python=3.9\n", " - pip\n", " - \u001b[94mpip\u001b[39;49;00m:\n", " - pandas\n", " - numpy\n", " - matplotlib\n", " - geopandas\n", " - shapely\n", " - folium\n", " - plotly_express\n", " - sentinelhub\n", " - rasterio\n", " - earthpy\n", " - conda\n", " - \u001b[94mconda\u001b[39;49;00m:\n", " - ipykernel \n" ] } ], "source": [ "!pygmentize environment.yml" ] }, { "cell_type": "markdown", "id": "7ae2f8de-ab22-4d43-947c-8261929b18a1", "metadata": { "tags": [] }, "source": [ "## Build Custom Environment\n", "Once you have your custom YAML file in SageMaker Studio Lab, you can build your custom environments in two ways " ] }, { "cell_type": "markdown", "id": "132eaee9-8ff8-4bd7-8e19-c4752763aa69", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "#### Method 1 - Using the SageMaker Studio Lab UI console\n", "Right click the YAML file from the SageMaker Studio Lab UI and choose to build an new environment \n", "\n", "![Create Environment](images/create_environment.png)" ] }, { "cell_type": "markdown", "id": "20e33c91-5b31-48ab-945e-4ffe6bcc56f2", "metadata": {}, "source": [ "#### Method 2 - Using the Terminal Console\n", "Open the terminal window using **File -> New -> Terminal**\n", "![New Terminal](images/new_terminal.png)" ] }, { "cell_type": "markdown", "id": "8b9a12c3-d1ed-46e4-962b-369efbc6e69a", "metadata": {}, "source": [ "Execute the following commands\n", "```\n", " $ conda env create -f environment.yml\n", " $ conda activate \n", "```\n" ] }, { "cell_type": "markdown", "id": "7ebb4e70-4d60-4566-9aa1-cecab52ec048", "metadata": {}, "source": [ "## Using Your Custom Environment\n", "Use the launcher buttom to create a new notebook\n", "\n", "![Launcher Button](images/launcher_button.png)" ] }, { "cell_type": "markdown", "id": "c0f812ef-7c4a-42d3-84e3-d41ace145ef5", "metadata": {}, "source": [ "Your custom environment should now appear in the launcher. Select this to create new notebook with your custom environment\n", "\n", "![Custom Launcher](images/custom_launcher.png)" ] }, { "cell_type": "markdown", "id": "66f904d8-6121-46fc-88b5-23266ca2a3e0", "metadata": { "tags": [] }, "source": [ "#### Import Packages\n", "After you create the notebook by choosing the custom environment, you can directly import your custom packages." ] }, { "cell_type": "code", "execution_count": null, "id": "0702c69d-ab5d-4bec-890b-ea454b3dc852", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import geopandas as gpd\n", "from shapely.geometry import Point\n", "import matplotlib\n", "import matplotlib.pyplot as plt \n", "import folium\n", "import plotly_express as px\n", "from sentinelhub import AwsTile\n", "from sentinelhub import AwsTileRequest\n", "import rasterio" ] } ], "metadata": { "kernelspec": { "display_name": ".conda-default-kernel:Python", "language": "python", "name": "conda-env-.conda-default-kernel-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }